标签:
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