Drag (parent Class)
functionDrag (ID) {var_this = This; This. DISX = 0; This. Disy = 0; This. Odiv =document.getElementById (ID); This. Odiv.onmousedown =function(EV) {_this.fndown (EV); return false; };} Drag.prototype.fnDown=function(EV) {var_this = This; varoevent = EV | |event; This. DISX = oevent.clientx- This. Odiv.offsetleft; This. Disy = oevent.clienty- This. Odiv.offsettop; Document.onmousemove=function(EV) {_this.fnmove (EV); }; Document.onmouseup=function() {_this.fnup (); };} Drag.prototype.fnMove=function(EV) {varoevent = EV | |event; This. ODiv.style.left = oevent.clientx- This. disx+ ' px '; This. ODiv.style.top = oevent.clienty- This. disy+ ' px ';} Drag.prototype.fnUp=function() {Document.onmousemove=NULL; Document.onmouseup=NULL;}/*window.onload=function () {var odiv = document.getElementById (' Div1 '); Odiv.onmousedown=function (EV) {var oevent = EV | | event; var disx = Oevent.clientx-odiv.offsetleft; var disy = oevent.clienty-odiv.offsettop; Document.onmousemove = function (ev) {var oevent = EV | | event; ODiv.style.left = oevent.clientx-disx+ ' px '; ODiv.style.top = oevent.clienty-disy+ ' px '; }; Document.onmouseup=function () {document.onmousemove=null; Document.onmouseup=null; }; }}*/
Limitdrag (Subclass)
functionLimitdrag (ID) {Drag.call ( This, id);} for(varIinchDrag.prototype) {Limitdrag.prototype[i]=drag.prototype[i];} LimitDrag.prototype.fnMove=function(EV) {varoevent = EV | |event; varL = oevent.clientx- This. Disx; vart = oevent.clienty- This. Disy; if(L < 0) {L=0; }Else if(L > document.documentelement.clientwidth- This. Odiv.offsetwidth) {L= document.documentelement.clientwidth- This. Odiv.offsetwidth; } This. ODiv.style.left = l + ' px '; This. ODiv.style.top = t + ' px ';}
Object-oriented drag (subclass inheritance)