td.οnmοusedοwn=function(){//鼠标按下this.style.cursor="move";//设置鼠标样式vard=document;a=window.event;//按下时创建一个事件varx=a.clientX-document.body.scrollLeft-objWin...
td.onmousedown = function () {//鼠标按下
this.style.cursor = "move"; //设置鼠标样式
var d = document;
a = window.event; //按下时创建一个事件
var x = a.clientX - document.body.scrollLeft - objWin.offsetLeft; //x=鼠标相对于网页的x坐标-网页被卷去的宽-待移动对象的左外边距
var y = a.clientY - document.body.scrollTop - objWin.offsetTop; //y=鼠标相对于网页的y左边-网页被卷去的高-待移动对象的左上边距
d.onmousemove = function () {//鼠标移动
a = window.event; //移动时创建一个事件
objWin.style.left = a.clientX + document.body.scrollLeft - x;
objWin.style.top = a.clientY + document.body.scrollTop - y;
};
d.onmouseup = function () {//鼠标放开
td.style.cursor = "normal"; //设置放开的样式
document.onmousemove = null;
document.onmouseup = null;
};
};
这是这是实现拖拽的代码
展开