Understanding the js--Event Object 5-

Source: Internet
Author: User

<! 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-

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.