The difference _javascript skill of scrollwidth,clientwidth,offsetwidth

Source: Internet
Author: User

Test the difference between these three properties through a demo.

Description

ScrollWidth: The width of the actual content of the object, not wrapping the edge width, increases as the contents of the object exceed the viewable area.
ClientWidth: The width of the visual area of the object's content, not wrapping the edges of the scroll bar, will change with the size of the object display.
Offsetwidth: The actual width of the object as a whole, the wrapping line, and so on, will change with the size of the object display.

The demo will put a TEXTAREA element in the page, using the default width-height display.

Situation 1:

There is no content in the element or the content does not exceed the viewable area, scrolling does not appear or is not available.

Scrollwidth=clientwidth, both are the width of the content viewable area.

Offsetwidth is the actual width of the element.

Situation 2:

The content of the element exceeds the viewable area, and the scroll bar appears and is available.

Scrollwidth>clientwidth.

ScrollWidth is the width of the actual content.

ClientWidth is the width of the content viewable area.

The offsetwidth is the actual width of the element.

End

The above is the whole content of scrollwidth,clientwidth,offsetwidth difference, hope to be helpful to everybody.

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.