onmousedown 和onmouseup應(yīng)該在哪一段代碼中寫?
看程序中,?? oTitle.onmousedown=fnDown; ?是作用在login_logo_webqq這個DIV的, 按道理, 那么onmouseup也應(yīng)該是作用在這個地方,為什么下面document.onmouseup是作用在document里面的事件? ?按道理, onmousedown和onmouseup是不是應(yīng)該寫在一個函數(shù)里面的? 因為不可能一直是onmousedown的狀態(tài)啊
function drag() ?{
? ? var oTitle=getclass("login_logo_webqq","loginPanel")[0];
? ? oTitle.onmousedown=fnDown;
}
function fnDown(event){
? ? event=event||window.event;
? ?var ?oDrag=document.getElementById("loginPanel");
? ? ?disX=event.clientX-oDrag.offsetLeft,
? ? ?disY=event.clientY-oDrag.offsetTop;
? ? ? document.onmousemove=function(event) {?
? ? ? ? event=event||window.event;
? ? ? ? fnMove(event,disX,disY);?
? ? ? }
? ? ? ?document.onmouseup=function() {document.onmousemove=null;
? ? ? ?document.onmouseup=null;
? ? ? ?}
}
2016-10-29
我看看試了課題里的代碼,把document改成otitle,效果實現(xiàn)的是一樣的,用document的話,可以不用再取一下那個otitle這變量,減少代碼的量。