For details about DOM element dimensions, such as offsetWidth, scrollWidth, and clientWidth, offsetwidth

Source: Internet
Author: User

For details about DOM element dimensions, such as offsetWidth, scrollWidth, and clientWidth, offsetwidth

Example:

<div id="div" style="height: 200px;width: 200px;border:solid 50px red;overflow:auto;padding:50px">    <div id="info" style="height:400px;width:400px;border:solid 1px blue;"></div>    <script>    var div=document.getElementById("div");    var ho=div.offsetHeight;    var hc=div.clientHeight;    console.log(ho,hc);    </script></div>
1. offsetWidth

OffsetWidth = border + padding + height;
Here: 50 + 50 + 200 + 50 + 50 = 400

Note:OffsetWidthYou cannot obtain the correct value in the div of display: none. You can use jquery'sOuterWidth ()Correct

2. clientWidth


ClientWidth = padding + height-Scroll bar
The value is 50 + 200 + 50-17 = 283.

Note: jquery'sInnerWidth ()Do not calculate the scroll bar. Expected result 300 is displayed.

3. scrollWidth


ScrollWidth = padding + full height of content contained
The value is 50 + 402 + 50 = 502.

4. scrollTop

Definition: gets the distance between the top boundary of the element and the top of the currently visible content in the element.

ScrollTop = scrollHeight-clientHeight
= Padding + full height of content included-(padding + height-scroll bar)
= Full height of the content included-height-scroll bar

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.