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> 

 


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.

An example of clientWidth and offsetWidth:

<Html> 


The value of offsetWidth is always greater than that of clientWidth.
ClientWidth is the width (excluding the edge) seen by the object)
OffsetWidth is the width seen by the object (including the edge, such as the width occupied by the scroll bar)

 

Ps:

Wrap = "virtual"Automatic line feed is implemented in the text area to improve user display. However, when transmitted to the server, the text is wrapped only when the user presses the Enter key, there is no line feed effect elsewhere.

Wrap = "physical"It implements automatic line breaks in the text area and transmits them to the server in this form, just as the user actually typed. Because text needs to be transmitted to the server based on the effect you see in the text area, it is very useful to use automatic line breaks.

If you set wrapOffTo obtain the default action.

Difference between scrollWidth, clientWidth and offsetWidth

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.