function drag (OBJ,SITE,FN) {
var DmW = Document.documentElement.clientWidth | | Document.body.clientWidth
var DmH = Document.documentElement.clientHeight | | Document.body.clientHeight
var site = Site | | {};
var adsorb = SITE.N | | 0; Adsorption range of magnetic adsorption
var L = SITE.L | | 0;
var r = (SITE.R | | site.r==0)? site.r:dmw-obj.offsetwidth;
var t = site.t | | 0;
var b = (site.b | | site.b==0)? site.b:dmh-obj.offsetheight;
Obj.onmousedown=function (EV) {
var oevent = EV | | Event
var Sitex = Oevent.clientx-obj.offsetleft;
var sitey = oevent.clienty-obj.offsettop;
if (obj.setcapture) {//compatible with IE low-version blocking default behavior and implement event capture
Obj.onmousemove=move;
Obj.onmouseup=up;
Obj.setcapture ();
}else{
Document.onmousemove=move;
Document.onmouseup=up;
}
function Move (EV) {
var oevent = EV | | Event
var ileft = Oevent.clientx-sitex;
var iTop = Oevent.clienty-sitey;
if (ILeft <=l+adsorb) {//Limit drag range
ileft=0;
}
if (ILeft >=r-adsorb) {
Ileft= R;
}
if (Itop<=t+adsorb) {
ITop = 0;
}
if (ITop >=b-adsorb) {
ITop = b;
}
if (FN) {//Executes the callback function if there are additional conditions that need to be handled
fn ({left:ileft,top:itop})
}else{
Obj.style.left = ileft + ' px ';
Obj.style.top = iTop + ' px ';
}
}
function up () {
This.onmousemove=null;
This.onmouseup=null;
Release Capture if (obj.setcapture) {//drag-and-drop ends
Obj.releasecapture ();
}
}
return false;
}
}
JS implementation of Drag wrapper function