Full explanation of HTML: scrollleft, scrollwidth, clientwidth, and offsetwidth

Source: Internet
Author: User
HTML: scrollleft, scrollwidth, clientwidth, and offsetwidth

Scrollheight: gets the scroll height of an object.
Scrollleft: sets or obtains the distance between the left-side border of the object and the leftmost end of the currently visible content in the window.
Scrolltop: sets or obtains the distance between the top of the object and the top of the visible content in the window.
Scrollwidth: gets the scroll width of an object.
Offsetheight: gets the height of an object relative to the layout or the parent coordinate specified by the parent coordinate offsetparent attribute.
Offsetleft: obtains the left position of the object relative to the layout or the parent coordinate specified by the offsetparent attribute.
Offsettop: obtains the top position of an object relative to the layout or the parent coordinate specified by the offsettop attribute.
The horizontal coordinates of event. clientx relative to the document
The vertical coordinates of event. clienty relative to the document

Horizontal coordinates of event. offsetx relative to the container
Event. offsety vertical coordinates of the container
Document.doc umentelement. scrolltop vertical scroll Value
Event.clientxw.document.doc umentelement. The horizontal coordinate of scrolltop relative to the document + The amount of vertical scrolling

The difference between Firefox and IE is as follows:
Ie6.0, ff1.06 +:
Clientwidth = width + padding
Clientheight = height + padding
Offsetwidth = width + padding + border
Offsetheight = height + padding + border
Ie5.0/5.5:
Clientwidth = width-border
Clientheight = height-border
Offsetwidth = width
Offsetheight = height
(The margin attribute in CSS is independent of clientwidth, offsetwidth, clientheight, and offsetheight)

Test Code :
Code: [copy to clipboard] <! Doctype
HTML public "-// W3C // dtd xhtml 1.0 transitional // en"
"[Url = Hangzhou">
<HTML xmlns = "[url = http://www.w3.org/5o/xhtml#http://www.w3.org/5o/xhtml#/url]" lang = "gb2312">
<Head>
<Head>
<Title> code example: test and comparison of clientwidth, offsetwidth, clientheight, and offsetheight </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Meta name = "author" content = "fengyan, CnLei.y.l@gmail.com">
<Meta name = "Copyright" content = "[url = http://www.cnlei.com] http://www.cnlei.com [/url]"/>
<Meta name = "Description" content = "test and comparison of clientwidth, offsetwidth, clientheight, and offsetheight"/>
<Style type = "text/CSS" Media = "all">
Body {font-size: 14px ;}
A, A: visited {color: # 00f ;}
# Div_cnlei {
Width: 300px;
Height: 200px;
Padding: 10px;
Border: 10px solid # CCC;
Background: # Eee;
Font-size: 12px;
}
# Div_cnlei P {margin: 0; padding: 10px; Background: # FFF ;}
</Style>
<SCRIPT type = "text/JavaScript">
Function OBJ (s ){
Return document. getelementbyid (s )? Document. getelementbyid (s): S;
}
Function getclientwidth (o ){
Return OBJ (O). clientwidth;
}
Function getclientheight (o ){
Return OBJ (O). clientheight;
}
Function getoffsetwidth (o ){
Return OBJ (O). offsetwidth;
}
Function getoffsetheight (o ){
Return OBJ (O). offsetheight;
}
</SCRIPT>
</Head>
<Body>
<P> click the following link: </P>
<Div id = "div_cnlei">
<P> <
Href = "javascript: Alert (getclientwidth ('div _ cnlei');"> getclientwidth (); </a> <
Href = "javascript: Alert (getclientheight ('div _ cnlei');"> getclientheight (); </a> </P>
<P> <
Href = "javascript: Alert (getoffsetwidth ('div _ cnlei');"> getoffsetwidth (); </a> <
Href = "javascript: Alert (getoffsetheight ('div _ cnlei');"> getoffsetheight (); </a> </P>
</Div>
<Div id = "Description">
<P> <strong> ie6.0, ff1.06 +: </strong> <br/>
Clientwidth = width + padding = 300 + 10 × 2 = 320 <br/>
Clientheight = height + padding = 200 + 10 × 2 = 220 <br/>
Offsetwidth = width + padding + border = 300 + 10 × 2 + 10 × 2 = 340 <br/>
Offsetheight = height + padding + border = 200 + 10 × 2 + 10 × 2 = 240 </P>
<P> <strong> ie5.0/5.5: </strong> <br/>
Clientwidth = width-border = 300-10 × 2 = 280 <br/>
Clientheight = height-border = 200-10 × 2 = 180 <br/>
Offsetwidth = width = 300 <br/>
Offsetheight = height = 200 </P>
</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.