2 回答
TA贡献1811条经验 获得超4个赞
当您向上移动鼠标时,函数closeDragElement()被调用并且事件监听器document.onmousemove被覆盖为“null”。
注释掉函数中的最后一行closeDragElement()可能会解决这个问题:
function closeDragElement() {
// alert(elmnt.id);
document.onmouseup = null;
// document.onmousemove = null;
}
编辑:添加一个变量mousedown来指示鼠标是否按下。
function dragWindow(elmnt) {
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
var mousedown = 0;
elmnt.querySelector(".window-caption").onmousedown = dragMouseDown;
function dragMouseDown(e) {
e.preventDefault();
mousedown++;
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
document.onmousemove = elementDrag;
}
function elementDrag(e) {
e.preventDefault();
if (mousedown === 0) {return;}
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
}
function closeDragElement() {
// alert(elmnt.id);
mousedown--;
document.onmouseup = null;
//document.onmousemove = null;
}
}
- 2 回答
- 0 关注
- 93 浏览
添加回答
举报