Source code Display
Where the HTML structure is as follows:
<div class= "Dustbin" ><br/> bin <br/> rubbish <br/> Box </div><div class= "Dragbox" > < Div class= "draglist" title= "Drag Me" draggable= "true" > List 1</div> <div class= "draglist" title= "Drag Me" Draggable= "true" > List 2</div> <div class= "draglist" title= "Drag Me" draggable= "true" > List 3</div> <div class= "draglist" title= "Drag Me" draggable= "true" > List 4</div> <div class= "draglist" title= " Drag Me "draggable=" true "> List 5</div> <div class=" draglist "title=" Drag Me "draggable=" true "> List 6</div ></div><div class= "Dragremind" ></div>
The JS code is as follows:
var $ = function (selector) {/* Simple Selector method */...}; var Eledustbin = $ (". Dustbin") [0], Eledrags = $ (". Draglist"), Ldrags = eledrags.length, Eleremind = $ (". Dragremind") [0], E Ledrag = Null;for (var i=0; i<ldrags; i+=1) {Eledrags[i].onselectstart = function () {return false; }; Eledrags[i].ondragstart = function (EV) {/* Drag to start */Drag effect ev.dataTransfer.effectAllowed = "move"; Ev.dataTransfer.setData ("text", Ev.target.innerHTML); Ev.dataTransfer.setDragImage (ev.target, 0, 0); Eledrag = Ev.target; return true; }; Eledrags[i].ondragend = function (EV) {/* Drag end */ev.dataTransfer.clearData ("text"); Eledrag = null; return false};} Eledustbin.ondragover = function (EV) { /* Drag element moves on the target element header */Ev.preventdefault (); return true;}; Eledustbin.ondragenter = function (EV) {/ * Drag element into the target element header */This.style.color = "#ffffff"; return true;}; Eledustbin.ondrop = function (EV) {/ * Drag the element into the target element header while the mouse is released */if (Eledrag) {eleremind.innerhtml = ' <strong> ' + eledrag.innerhtml + ' </strong> was thrown into the dustbin '; EleDrag.parentNode.removeChild (Eledrag); } This.style.color = "#000000"; return false;};
HTML5 drag-and-Drop API (code show)