读书人

面临对像的拖拽

发布时间: 2012-11-25 11:44:31 作者: rapoo

面向对像的拖拽
function Drag(obj){
this.oBox= document.getElementById(obj);
this.disX =0;
this.disY =0;
var slef =this;
this.oBox.onmousedown=function(ev){
self.dragDown(ev)
}
}

Drag.prototype={
dragDown:function(ev){

this.disX =ev.clientX - this.oBox.offsetLeft;
this.disY = ev.clientY - this.oBox.offsetRight;
var self = this;
document.onmousemove = function(ev){

self.dragMove(ev);
}
document.onmouseup = function(ev){

document.onmousemove=null;
document.onmouseup =null;
}

return false;
},

dragMove:function(ev){

var L = ev.clientX -this.disX;
var Y = ev.clientY - this.disY;
this.oBox.style.left = L + 'px';
this.oBox.style.top =Y + 'px';

}
}

读书人网 >Web前端

热点推荐