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;
};
}

posted on 2016-05-23 13:07  Swift凌风  阅读(148)  评论(0编辑  收藏  举报