JS Drag Technology---about setcapture (transfer from Jean-. NET Learning Notes)
Copy Code code as follows:
<script type= "Text/javascript" >
<!--
Window.onload=function () {
Objdiv = document.getElementById (' drag ');
Drag (Objdiv);
};
function drag (DV) {
Dv.onmousedown=function (e) {
var d=document;
E = e | | window.event;
var x= E.layerx | | E.offsetx;
var y= e.layery | | E.offsety;
Set Capture Range
if (dv.setcapture) {
Dv.setcapture ();
}else if (window.captureevents) {
Window.captureevents (Event.mousemove | Event.mouseup);
}
D.onmousemove=function (e) {
E= E | | window.event;
if (!e.pagex) E.pagex=e.clientx;
if (!e.pagey) E.pagey=e.clienty;
var tx=e.pagex-x;
var ty=e.pagey-y;
DV.STYLE.LEFT=TX;
Dv.style.top=ty;
};
D.onmouseup=function () {
To cancel the capture range
if (dv.releasecapture) {
Dv.releasecapture ();
}else if (window.captureevents) {
Window.captureevents (event.mousemove| Event.mouseup);
}
Purge events
D.onmousemove=null;
D.onmouseup=null;
};
};
}
-->
</script>
<div id= "Drag" style= "position:absolute;left:12px;top:24px;width:100;height:150;border:1px solid #000000; Z-index:1;background: #eeeeee ">drag me</div>