HTML5 drag-and-drop operation

Source: Internet
Author: User

An interesting drag-and-drop effect recently seen in HTML5, here is a simple drag-and-drop effect on the deleted element.


<! DOCTYPE html>

<meta charset= "UTF-8" >
<title> drag and drop operations </title>
<style>
li{list-style:none;width:100px; height:100px; background:red; margin-bottom:20px;}
#div1 {width:200px; height:200px; background:red; margin:0 Auto;}
</style>
<script>
Window.onload = function ()
{
var Oul = document.getElementsByTagName ("ul") [0];
var aLi = oul.getelementsbytagname ("Li");
var odiv = document.getElementById ("Div1");


var i = 0;
for (var i=0; i<ali.length; i++)
{
Ali[i].index = i;
Ali[i].ondragstart =function (EV)
{
var ev = EV | | window.event;
Ev.dataTransfer.setData (' name ', This.index);
This.style.background = "green";
};


Ali[i].ondrag =function ()//start and end continuous triggering
{
Document.title = i++;
};


Ali[i].ondragend =function ()
{
This.style.background = "Red";
};
}


Odiv.ondragenter = function ()
{
This.style.background = "Blue";
}
Odiv.ondragleave = function ()
{
This.style.background = "Red";
}
Odiv.ondragover = function (EV)//start and end continuous triggering
{


To trigger a drop event, you must block the default event in the OnDragOver event
Document.title = i++;
Ev.preventdefault ();
}
odiv.ondrop= function (EV)
{
This.style.background = "Yellow";
Alert (Ev.dataTransfer.getData ("name"));
Oul.removechild (Ali[ev.datatransfer.getdata ("name")]);


for (var i=0; i<ali.length; i++)
{
Ali[i].index = i;
}
}


}
</script>
<body>
<ul>
<li draggable= "true" ></li>
<li draggable= "true" ></li>
<li draggable= "true" ></li>
<li draggable= "true" ></li>
</ul>


<div id= "Div1" ></div>




</body>



It is a small picture of the above drag and drop in the generous box below to release the mouse to delete the current drag and drop of the thumbnail.

HTML5 drag-and-drop operation

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.