PHP
·
发表于 5年以前
·
阅读量:8410
function drag(index){
index.onmousedown = function(event){
var ev = event ||window.event;
ev.preventDefault();
disX = ev.clientX-this.offsetLeft;
disY = ev.clientY-this.offsetTop;
//给index绑定moousemove事件
document.onmousemove = function(event){
var ev = event ||window.event;
ev.preventDefault();
var x = ev.clientX;
var y = ev.clientY;
index.style.left = x-disX+'px';
index.style.top = y-disY+'px';
}
}
document.onmouseup =function(){
document.onmousemove = null;
}
}