Drag and Drop in HTML 5
(DnD) is a great user interface concept that makes it easy to copy, reorder and delete items with the help of a mouse click. This allows the user to click and hold the mouse button on an item, drag the item to another location, and release the mouse button to drop that item.
To use drag-and-drop functionality with traditional HTML4, developers must use complex JavaScript programming or jQuery, etc. They must use other JavaScript components, such as,
HTML 5 now offers a Drag and Drop (DnD) API that brings native DnD support to browsers for easy customization. HTML 5 DnD is supported by all major browsers (for example, Chrome, Firefox 3) 5 and Safari 4, etc.
Drag and Drop Events
Numerous events are triggered at various stages of the drag-and-drop operation. The events are listed below -
- Dragstart- Raised when the user starts dragging objects.
- Dragenter- Fires the first time the mouse moves over the target while a dragon is present. Listeners of this event should be informed whether it is allowed to be posted on this site. Destruction is not allowed by default if there is no listener or the listener does nothing.
- Drag Over- This event is triggered when the mouse hovers over the item when a drag occurs. In general, what happens during the trial will be similar to dragenter events.
- Dragleave- This event is triggered when the mouse leaves the element during the mission. Listeners should remove important content or information used to discard feedback.
- Drag- Triggered every time the mouse moves while dragging an object.
- Drop- Raises a drop event on the element where the drop occurred at the end of the drag operation. The listener will be responsible for retrieving the data dragged and inserted at the drop point.
- Dragend- Raised when the user releases the mouse button while dragging an object.
DataTransfer object
Each drag-and-drop event listener receives an event object with a read-only property named dataTransfer.
event.dataTransfer Returns the DataTransfer object associated with the event, as shown below.
function EnterHandler(event) {
DataTransfer dt = event.dataTransfer;
.............
}
The DataTransfer object holds information about the drag-and-drop operation. These data can be retrieved and set as various objects associated with the DataTransfer object, as described below.
dataTransfer.dropEffect [ = value ]

Join the conversation! Your thoughts help the community grow.