鼠標松開依舊移動
function fnDown(event){
? ?event=event || window.event;
? ?//光標按下時光標和面板之間的距離
? ?var disX=event.clientX-login_box.offsetLeft;
? ?var disY=event.clientY-login_box.offsetTop;
? ?//mousemove:當鼠標指針在元素內部移動時重復的觸發(fā)
? ?addEvent(document,'mousemove',function(event){
? ? ? ?event=event || window.event;
? ? ? ?winw=document.documentElement.clientWidth||document.body.clientWidth;
? ? ? ?winh=document.documentElement.clientHeight||document.body.clientHeight;
? ? ? ?maxW=winw-login_box.offsetWidth;
? ? ? ?maxH=winh-login_box.offsetHeight;
? ? ? ?var w=event.clientX-disX;
? ? ? ?var h=event.clientY-disY;
? ? ? ?//不出邊界
? ? ? ?if(w<0){
? ? ? ? ? ?w=0;
? ? ? ?}else if(w>maxW){
? ? ? ? ? ?w=maxW;
? ? ? ?}
? ? ? ?if(h<0){
? ? ? ? ? ?h=0;
? ? ? ?}else if(h>maxH){
? ? ? ? ? ?h=maxH;
? ? ? ?}
? ? ? ?login_box.style.left=w+'px';
? ? ? ?login_box.style.top=h+'px';
? ?})
? ?//釋放鼠標
? ?document.onmouseup=function(){
? ? ? ?document.onmousemove=null;
? ? ? ?document.onmouseup=null;
? ?}
}
2017-03-06
用addEventListener(或attachEvent)添加的事件,必須用removeEventListener(或detachEvent)移除