Translation article by Sara Vieira will show you how easy it is to implement drag&drop functionality in HTML5 with a pinch of JavaScript.
Although there have long been all kinds of functions in JavaScript that allow creating an interface for drag&drop functionality, none of these implementations could be consider native from the perspective of a web browser. However, it is possible in HTML5 – with a little help of JavaScript, of course – and this article will show you how.
The article was translat with the kind permission of webdesignerdepot.com . The original text of the article (EN) can be found here: How to use HTML5′s drag and drop .
Support in browsers
Before we continue, I want to make one thing clear – the current mouse-drag method is support in HTML by all major desktop browsers, including IE (even IE 5.5 has partial support), but is currently not support by any mobile browser.
Mouse drag events
At each stage of dragging elements with the mouse, various events are fir that allow the browser to recognize which JavaScript code to actually execute. These are the following events:
dragStart: fires when the user starts dragging an element.
dragEnter: Fires when the draggable element is dragg over the target element for the first time.
dragOver: Fires when the mouse moves over the element while dragging.
dragLeave: fires when the user’s cursor iraq phone number data drops an element while dragging.
drag: Fires every time the mouse moves while dragging an element.
drop: fires when the draggable is dropp.
dragEnd: fires when the user releases make sure your contact the mouse while dragging an object.
All of these event listeners give
you a lot of control over the functionality of the interface and the execution of drag and drop in different circumstances.
The dataTransfer object
This is where all the drag and drop cz lists magic happens – this object contains the data to be mov. Data can be set and retriev in a variety of ways.