码迷,mamicode.com
首页 > 其他好文 > 详细

拖拽原理

时间:2016-05-23 15:00:24      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

function drag(obj) {
obj.onmousedown = function(ev) {
var ev = ev||event;
var disX = ev.clientX - this.offsetLeft;
var disY = ev.clientY - this.offsetTop;

if(obj.setCapture) {
obj.setCapture();
}

obj.onmousemove = function(ev) {
var ev = ev||event;
var L = ev.clientX - disX;
var T = ev.clientY - disY;

if(L<0) {
L = 0;
} else if(L>document.documentElement.clientWidth-obj.offsetWidth) {
L = document.documentElementElement.clientWidth - obj.offsetWidth;
}

if(T<0){
T = 0;
} else if(T>document.documentElement.clientHeight-obj.offsetHeight) {
T = document.documentElement.clientHeight - obj.offsetHeight;
}

obj.style.left = L + ‘px‘;
obj.style.top = T + ‘px‘;
};

obj.onmouseup = function()
{
obj.onmoseup = obj.onmousemove = null;
if(obj.releaseCapture)
{
obj.releaseCapture();
}
};
return false;
};
}

拖拽原理

标签:

原文地址:http://www.cnblogs.com/xiewei1412125225/p/5519590.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!