Copy code code as follows:
/*
Drag-and-drop process:
1, first click on the element you want to drag
2, the element under Click is selected, Move moves
3, when the mouse is bouncing Wait, stop the action
4, click Element Odiv, the available is the Odiv area, and move and up is the global area, that is, the entire document universal, that is, should use document
/
Odiv = document.getElementById ("Gaga");
Odiv.onmousedown = function (e) {//When the mouse clicks down
var diffx = e.clientx-odiv.offsetleft;//Click on the location from the leftmost position of the browser (CLI ENTX) subtracting the clicked element from the leftmost position (Odiv.offetleft) is indeterminate at the left-most position of the clicked element, so this result is required
var diffy = e.clienty-odiv.offsettop;//Point The position of the hit from the top of the browser (ClientY) minus the position of the clicked element from the top (odiv.offsettop) is indeterminate at the top position of the clicked element, so this result is required
Document.onmousemove = Function (e) {//When the mouse button is pressed
var e = e | | window.event;
ODIV.style.top = e.clienty-diffy + "px";
ODIV.style.left = e.clientx-diffx + "px";
};
Document.onmouseup = function () {//When the mouse is bouncing
Document.onmousemove = null;//empty mouse down event
Document.onmous EuP = null; Empty the mouse to bounce the event
}
};