HTML5 drag-and-Drop API (code show)

Source: Internet
Author: User

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)

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.