Recently briefly looked at about HTML5 drag-and-drop related content, now will organize the knowledge to write down:
I. Relevant FOCUS
- DataTransfer object: The medium that the object is used to pass, used generally as event.datatransfer.
- 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>
- Ondragstart Event: An event that is triggered when a drag element starts being dragged, and this event acts on the dragged element
- OnDragEnter Event: An event that fires when a dragged element enters the target element, which acts on the target element
- OnDragOver Event: An event that is triggered when a drag element is moved on the target element, which acts on the target element
- OnDrop event: The dragged element on the target element with the mouse release of the triggered event, which acts on the target element
- Ondragend Event: An event triggered when a drag is completed, which acts on the dragged element
- 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.
- 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