//在控制台输出a.js:85 Uncaught ReferenceError: disY is not defined at HTMLDocument.document.onmouseover ,但也disY也没在onmouseover下,它是在 onmousemove的函数中定义的 function fnDown(e) { e = e || window.event; var oDarg = document.getElementById('loginPanel'), ow = oDarg.offsetLeft, oh = oDarg.offsetTop, ew = e.clientX, eh = e.clientY, disX = ew - ow, disY = eh - oh; document.onmousemove = function (e) { e = e || window.event; fnMove(e, disX, disY); } document.onmouseup = function () { document.onmousemove = null; document.onmouseup = null; } }
function fnMove(e,posX,posY){ var oDrag=document.getElementById('loginPanel'), l=e.clientX-posX, //是变化的值 t=e.clientY-posY, 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<0){ t=10; }else if(t>maxH){ t=maxH; } oDrag.style.left=l+'px'; oDrag.style.top=t+'px'; }
fnMove(e, disX, disY); 这个方法是怎么写的?
它说你没定义 那你把
var oDarg = document.getElementById('loginPanel'),
ow = oDarg.offsetLeft,
oh = oDarg.offsetTop,
ew = e.clientX,
eh = e.clientY,
disX = ew - ow,
disY = eh - oh;
放到
document.onmousemove = function (e) {
e = e || window.event;
fnMove(e, disX, disY);
}
这里面试试。