Web front-end study notes-the difference between scrollWidth, clientWidth, and offsetWidth_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:51:24
Original
1097 people have browsed it

Test the difference between these three attributes through a demo.

Description:

scrollWidth: The width of the actual content of the object, excluding the edge width, will increase as the content in the object exceeds the visible area.
clientWidth: The width of the visual area of ​​the object content, excluding scroll bars and other edges, will change as the display size of the object changes.
offsetWidth: The actual width of the entire object, including scroll bars and other edges, will change as the display size of the object changes.

This demo puts a textarea element on the page and uses the default width and height.

Case 1: There is no content in the

element or the content does not exceed the visible area, and scrolling does not appear or is unavailable.

scrollWidth=clientWidth, both are the width of the content visible area.

offsetWidth is the actual width of the element.

Case 2: The content of the

element exceeds the visual 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 visual area.

offsetWidth is the actual width of the element.

and above.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template