BIN_GOD
2017-04-27 10:46
下面这个代码:
function fnDown() {
var oDrag = document.getElementById('loginPanel');
//document.title = event.clientX + ',' + event.clientY; //显示鼠标坐标
var disx = event.clientX - oDrag.offsetLeft;
var disy = event.clientY - oDrag.offsetTop;
//移动
document.onmousemove = function (event) {
event = event || window.event;
var l = event.clientX - disx;
var t = event.clientY - disy;
var winW = document.documentElement.clientWidth || document.body.clientWidth,
winH = document.documentElement.clientHeight || document.body.clientHeight,
maxW = winW - oDrag.offsetWidth - 10,
maxH = winH - oDrag.offsetHeight;
if (l < 0) {
l = 0;
} else if (l > maxW) {
l = maxW;
}
if (t < 10) {
t = 10;
} else if (t > maxH - 10) {
t = maxH;
}
oDrag.style.left = l + 'px';
oDrag.style.top = t + 'px'
}
//释放
document.onmouseup = function () {
document.onmousemove = null;
document.onmouseup = null;
}
}
我把释放那一块移出fnDown,在拖动的时候。第一次拖动鼠标然后松开鼠标是正常的,第二次拖鼠标的时候再送开鼠标,释放的程序就好像没执行一样,光标移至和图片一起移动。请问这是为什么?
没有按下去哪里的的释放之说呢?也就说释放是建立在按钮已经按下的前提下,所以要放在按下的里面
DOM事件探秘
99545 学习 · 1197 问题
相似问题