Details about DOM element dimensions, such as offsetWidth, scrollWidth, and clientWidth

Source: Internet
Author: User

Details about DOM element dimensions, such as offsetWidth, scrollWidth, and clientWidth

Example:

  
<script> var div=document.getElementById(div); var ho=div.offsetHeight; var hc=div.clientHeight; console.log(ho,hc); </script> 
1. offsetWidth 

OffsetWidth = border + padding + height;
Here: 50 + 50 + 200 + 50 + 50 = 400 <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Authorization + signature/Signature/ci3u/g1wzwvcd4nc1_vymxvy2txdw90zt4ncjxomibpzd0 = "2 clientwidth"> 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

 

Related Article

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.