Offsettop, clientx, clienttop, clientwidth, and offsetwidth coordinates.

Source: Internet
Author: User

These attributes are completely compatible with IE Firefox. If you do not need to mention them, you can see the test results:

[Source code]

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> </title>

<SCRIPT type = "text/JavaScript">
Function position (Eve ){
VaR T = Document. getelementbyid ("div1 ");
VaR E = Eve | event;
VaR divoffsettop = T. offsettop; // = Top + marginwidth = 100 + 3 = 103
VaR divoffsetleft = T. offsetleft; // left + marginwidth = 50 + 3 = 53
VaR eventtop = E. clienty;
VaR eventleft = E. clientx;
VaR divtop = T. style. Top;
VaR divleft = T. style. Left;
VaR divclienttop = T. clienttop; // borderwidth
VaR divclientleft = T. clientleft; // borderwidth
VaR divclientwidth = T. clientwidth; // width + 2 paddingwidth = 200 + 2*11 = 222
VaR divclientheight = T. clientheight; // height + 2 paddingwidth = 300 + 2*11 = 322
VaR divoffsetwidth = T. offsetwidth; // = 2 borderwidth + width + 2 paddingwidth = 2*7 + 200 + 2*11 = 236
VaR divoffsetheight = T. offsetheight; // = 2 borderwidth + height + 2 paddingwidth = 2*7 + 300 + 2*11 = 336
VaR bodyclienttop = Document. Body. clienttop;
VaR bodyclientleft = Document. Body. clientleft;
VaR divwidth = T. style. width;
VaR divheight = T. style. height;
VaR divborderwidth = T. style. borderwidth;
VaR divpaddingwidth = T. style. padding;
VaR divmaginwidth = T. style. margin;
VaR r = "divoffsetleft:" + divoffsetleft + "-- divoffsettop:" + divoffsettop; // 103 53
R + = "\ neventleft:" + eventleft + "-- eventtop:" + eventtop; // >=103> = 53
R + = "\ ndivleft:" + divleft + "-- divtop:" + divtop; // 100px 50px
R + = "\ ndivclientleft:" + divclientleft + "-- divclienttop:" + divclienttop; // 7 7
R + = "\ nbodyclientleft:" + bodyclientleft + "-- bodyclienttop:" + bodyclienttop; // 5
R + = "\ ndivclientwidth:" + divclientwidth + "-- divclientheight:" + divclientheight; // 222 322
R + = "\ ndivwidth:" + divwidth + "-- divheight:" + divheight; // 200 300
R + = "\ ndivoffsetwidth:" + divoffsetwidth + "-- divoffsetheight:" + divoffsetheight; // 236 336
R + = "\ ndivborderwidth:" + divborderwidth // 7px
R + = "\ ndivmaginwidth:" + divmaginwidth // 3px
Alert (R );
}
</SCRIPT>

</Head>
<Body>
<Input type = "button" id = "BTN" value = "test location"/>
<Br/>
<Div id = "div1" line-Height: normal; ">
Top: 50px; left: 100px; Border: 7px solid red; padding: 11px; margin: 3px; "onmousedown =" position (event) ">
This isArticleThis is the content of the article.
This is the content of the article.
This is the content of the article.
</Div>
</Body>
</Html>

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.