我有这个用于创建可移动窗口(元素)的代码,当我创建一个新窗口时我调用这个函数:
function dragWindow(elmnt) {
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
elmnt.querySelector(".window-caption").onmousedown = dragMouseDown;
function dragMouseDown(e) {
e.preventDefault();
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
document.onmousemove = elementDrag;
}
function elementDrag(e) {
e.preventDefault();
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);
document.onmouseup = null;
document.onmousemove = null;
}
}
问题是:
如果我创建一个新窗口,我不能移动他们之前创建的窗口。