HTML5 Drag & Drop drag and drop introduction

Source: Internet
Author: User

Recently briefly looked at about HTML5 drag-and-drop related content, now will organize the knowledge to write down:

I. Relevant FOCUS
    1. DataTransfer object: The medium that the object is used to pass, used generally as event.datatransfer.
    2. Draggable Property: is the label element to set the draggable=true, otherwise there will be no effect, for example:
      <div title= "Drag Me" draggable= "true" > List 1</div>
    3. Ondragstart Event: An event that is triggered when a drag element starts being dragged, and this event acts on the dragged element
    4. OnDragEnter Event: An event that fires when a dragged element enters the target element, which acts on the target element
    5. OnDragOver Event: An event that is triggered when a drag element is moved on the target element, which acts on the target element
    6. OnDrop event: The dragged element on the target element with the mouse release of the triggered event, which acts on the target element
    7. Ondragend Event: An event triggered when a drag is completed, which acts on the dragged element
    8. Event.preventdefault () Method: Prevents execution of the default event methods. Be sure to execute preventdefault () in OnDragOver, otherwise the OnDrop event will not be triggered. In addition, if you are dragging things from other applications or files, especially images, the default action is to display the image or related information, not to actually perform the drop. At this point, you need to use the document OnDragOver event to kill it directly.
    9. Event.effectallowed property: Is the effect of drag and drop. (Above transferred from Http://www.zhangxinxu.com/wordpress/2011/02/html5-drag-drop-%E6%8B%96%E6%8B%BD%E4%B8%8E%E6%8B%96%E6%94%BE %e7%ae%80%e4%bb%8b/)
Second, DataTransfer object

The DataTransfer object provides access to the predefined Clipboard formats for use in drag-and-drop operations.

It is popular to say that in the process of dragging, we can use the DataTransfer object to transfer data, so that when the drag operation at the end of the data for other operations.

Object Properties

    • DropEffect: Sets or returns the drag-and-drop behavior that is allowed on the drop target. If the drag-and-drop behavior set here no longer effectallowed within the various drag-and-drop behaviors of the property setting, the drag-and-drop operation will fail. This property value is allowed only for one of the four values of "null", "copy", "link", and "move".
    • Effectallowed: Sets or returns the drag behavior that is allowed to occur by the dragged element. The value of this property can be set to None, Copy, Copylink, Copymove, Link, linkmove, move, all, and uninitialized.
    • Items: This property returns the Datatransferitems object that represents the drag data.
    • Types: This property returns a Domstringlist object that contains all the types of data stored in the datatransfer.

Object methods

    • SetData (Format,data): Assigns the data of the specified format to the DataTransfer object, the parameter format defines the data as the type of data, and data is the value to be assigned.
    • GetData (format): Gets the data in the specified format from the DataTransfer object, formatted for the data format, and data for it.
    • ClearData ([format]): Removes data from the DataTransfer object in the specified format, and the parameter is optional, if not given, to delete all data in the object.
    • AddElement (Element): Adding a custom icon
    • Setdragimage (element,x,y): Sets the custom icon for the drag-and-drop operation. Where element sets the custom icon, the x sets the distance between the icon and the mouse in the horizontal direction, and the y sets the distance between the icon and the mouse in the vertical direction.

HTML5 Drag & Drop drag and drop introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.