标签:style blog color io ar div cti sp log
拖拽,主要用到onmousedown、onmouseover、onmouseup
拖拽的流程:(1)先点击
(2)在点下的物体被选中,进行move移动
(3)抬起鼠标,停止移动
【注】点击某个物体时,用oDiv即可,move和up是全局区域,也就是整个文档通用,应该用document。
oDiv.onmousedown = function(){ document.onmousemove = function(){ var e = e || window.event; var diffX = e.clientX - oDiv.offdsetLeft; var diffY = e.clientY - oDiv.offdsettop; var _this = this; _this.style.left = e.clientX - diffX + ‘px‘; // 鼠标点击哪里就可以从哪里开始拖拽 _this.style.top = e.clientY - diffY + ‘px‘; } document.onmouseup = function(){ this.onmousemove = null; this.onmouseup = null; } }
未完待续......^^
标签:style blog color io ar div cti sp log
原文地址:http://www.cnblogs.com/tracylyx/p/drag.html