為什么釋放鼠標不起作用?
//IE10-不支持getElementsByClassName
function getClass(className, parent) {
var oParent = parent ? document.getElementById(parent) : document;
var eles = [];
var elem = oParent.getElementsByTagName("*");
// alert(elem.length);
for (var i = 0; i < elem.length; i++) {
// alert(elem[0].className);
if (elem[i].className == className) {
eles.push(elem[i]);
}
}
return eles;
}
window.onload = drap;
function drap() {
var login = getClass("login_logo_webqq", "loginPanel")[0];
// var login = document.getElementsByClassName("login_logo_webqq")[0];
var loginPanel = document.getElementById("loginPanel");
// alert(login.className);
login.onmousedown = mDown;
function mDown(e) {
// alert("hello");
var postX, postY;
e = e || window.event;
postX = e.clientX - loginPanel.offsetLeft;
// alert(postX);
postY = e.clientY - loginPanel.offsetTop;
document.onmouseover = function(e) {
e = e || window.event;
mMove(e, postX, postY);
// alert(postX+" "+postY);
}
// 釋放鼠標
document.onmouseup = function() {
document.onmousemove = null;
document.onmouseup = null;?
}
}
function mMove(e, postX, postY) {
var e = e || window.event;
var x, y;
x = e.clientX - postX;
y = e.clientY - postY;
// alert(x);
// 整個顯示區(qū)域的寬度
var winW = document.documentElement.clientWidth || document.body.clientWidth;
winH = document.documentElement.clientHeight || document.body.clientHeight;
// alert(winW);
var offW = loginPanel.offsetWidth,
// alert(offW);
offH = loginPanel.offsetHeight;
var moveW = winW - offW,
moveH = winH - offH;
// alert(moveW);
if (x < 0) {
x = 0
} else if (x > moveW) {
x = moveW - 10;
}
if (y < 0) {
y = 10;
} else if (y > moveH) {
y = moveH;
}
loginPanel.style.left = x + 'px';
loginPanel.style.top = y + 'px';
document.title = x + " " + y;
}
}
2016-08-17
document.onmouseover = function(e) {}
寫錯了吧,應(yīng)該是 onmousemove
2016-09-08
document.onmouseup = null;
?可以把這句注釋了看看