<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">#div1 {width:100px; height:100px; background:red; position:absolute;}</style><meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/><title> Towing </title><script>window.onload=function (){ varOdiv=document.getelementbyid (' Div1 '); varDisx=0; varDisy=0; Odiv.onmousedown=function(EV) {varoevent=ev| |event; DISX=oevent.clientx-Odiv.offsetleft; Disy=oevent.clienty-Odiv.offsettop; Document.onmousemove=function(EV)//Document.onmousemove to document add event, prevent the mouse to drag quickly, the mouse is not moving area. { varoevent=ev| |event; varL=OEVENT.CLIENTX-DISX;//left margin variable varT=oevent.clienty-disy;//Right margin variable if(l<0) {L=0; } Else if(L>document.documentelement.clientwidth-odiv.offsetwidth)//The visual area size of the page-div the left value =div the distance{L=document.documentelement.clientwidth-Odiv.offsetwidth; } if(t<0) {T=0; } Else if(t>document.documentelement.clientheight-odiv.offsetheight) {T=document.documentelement.clientheight-odiv.offsetheight;//the visual area height of the page-div top value =div top margin distance} oDiv.style.left=l+ ' px '; ODiv.style.top=t+ ' px '; }; Document.onmouseup=function() {Document.onmousemove=NULL; Document.onmouseup=NULL; }; return false;//prevent Firefox from dragging the default event of the forbidden symbol two times };}; //there will be a problem when the browser is reset, the BOM onresize when added</script>Understanding the js--Event Object 5-