面向对象拖拽
function Drag(){
this.logo=document.getElementsByClassName("f-logo")[0];
this.enter=document.getElementsByName("enter")[0];
this.logo.onmousedown = function(e){
_this.down(e);
}
}
Drag.prototype.down = function(e){
var _this = this;
var e = e||event;
this.divX = e.offsetX;
this.divY = e.offsetY;
document.onmousemove = function(e){
_this.mov(e)
}
document.onmouseup = function(){
_this.up()
}
}
Drag.prototype.mov = function(e){
var e = e||event;
this.enter.style.left = e.clientX- this.divX +'px';
this.enter.style.top = e.clientY-this.divY+'px';
}
Drag.prototype.up = function(){
document.onmousemove = null;
document.onmouseup = null;
}
new Drag();