Difference between scrollwidth, clientwidth and offsetwidth

Source: Internet
Author: User

Scrollwidth
It is the width of the actual content of the object. The width of the content in the object varies with the number of elements in the object. If the content is too large, the actual width of the object may be changed ).
Clientwidth
It is the visible width of the object. If it is not set to the same side of the scroll bar, it will change with the display size of the window.
Offsetwidth
Is the visible width of the object. The package's scroll bar and other edges change with the display size of the window.

An example of scrollwidth and clientwidth:
<HTML>
<Head>
<Title> 77.htm file </title>
</Head>
<Body>
<Textarea wrap = "off" onfocus = "alert ('rollwidth: '+ this. scrollwidth +' \ n clientwidth: '+ this. clientwidth);"> </textarea>
</Body>
</Html>
Enter the content in the text box. The value of scrollwidth and clientwidth is the same before the horizontal scroll bar does not come out. When a row of content exceeds the width of the text box, a horizontal scroll bar is displayed, and the value of scrollwidth is changed.
Scrollwidth is the width of the object content.
Clientwidth is the width (excluding the edge) seen by the object, which will not be changed in this example.

example of clientwidth and offsetwidth:


77.htm file





the value of offsetwidth is always greater than that of clientwidth.
clientwidth indicates the width (excluding edges) of the object.
offsetwidth indicates the width (including edges, such as the width occupied by the scroll bar) of the object.

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.