Drag.prototype = {
mousedown: function(dom) {
var that = this;
dom.onmousedown=function(e) {
var ev=e || event;
that.disX=ev.clientX-dom.offsetLeft;
that.disY=ev.clientY-dom.offsetTop;
document.onmousemove=function(e){
var ev=e||event;
dom.style.left=ev.clientX-that.disX+'px';
dom.style.top=ev.clientY-that.disY+'px';
};
that.mouseup();
};
},
mouseup: function () {
document.onmouseup=function () {
document.onmousemove=null;
document.onmouseup=null;
}
},
init:function (dom){
this.mousedown(dom);
}
};
var dd = new Drag();
var oDiv= document.getElementById('div1');
dd.init(oDiv);
Stardust1001
相关分类