간단한 팝업 상자 드래그 닫기 이벤트

2236 단어 프런트엔드



    
             
    


×
var Close=document.getElementById('close'); Close.οnclick=function(){ box.style.display='none'; }; box.οnmοusedοwn=function(e){ var ev= e||event; var l=ev.clientX-box.offsetLeft; var t=ev.clientY-box.offsetTop; document.οnmοusemοve=function(e){ var ev = e||event; var needLeft=ev.clientX-l; var needTop=ev.clientY-t; // needLeft<0?needLeft=0:needLeft; // needTop<0?needTop=0:needTop; // var maxLeft=innerWidth-box.offsetWidth; needLeft>maxLeft?needLeft=maxLeft:needLeft; // var maxTop=innerHeight-box.offsetHeight; needTop>maxTop?needTop=maxTop:needTop; box.style.left=needLeft+'px'; box.style.top=needTop+'px'; }; document.οnmοuseup=function(){ document.οnmοusemοve=document.οnmοuseup=null; }; }

좋은 웹페이지 즐겨찾기