各种width,offsetWidth, getBoundingClientRect(), clientWidth,scrollWidth区别
来源:互联网 发布:中南大学网络教育电话 编辑:程序博客网 时间:2024/06/16 15:52
各种width,offsetWidth, getBoundingClientRect(), clientWidth,scrollWidth区别
搬运自https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/Determining_the_dimensions_of_elements
How much room does it use up?
If you need to know the total amount of space an element occupies, including the width of the visible content, scrollbars (if any), padding, and border, you want to use the offsetWidth and offsetHeight properties. Most of the time these are the same as width and height of getBoundingClientRect(), when there aren’t any transforms applied to the element. In case of transforms, the offsetWidth and offsetHeight returns the element’s layout width and height, while getBoundingClientRect() returns the rendering width and height. As an example, if the element has width: 100px; and transform: scale(0.5); the getBoundingClientRect() will return 50 as the width, while offsetWidth will return 100.
What’s the size of the displayed content?
If you need to know how much space the actual displayed content takes up, including padding but not including the border, margins, or scrollbars, you want to use the clientWidth and clientHeight properties:
How big is the content?
If you need to know the actual size of the content, regardless of how much of it is currently visible, you need to use the scrollWidth and scrollHeight properties. These return the width and height of the entire content of an element, even if only part of it is presently visible due to the use of scroll bars.
For example, if a 600x400 pixel element is being displayed inside a 300x300 pixel scrollbox, scrollWidth will return 600 while scrollHeight will return 400.
- 各种width,offsetWidth, getBoundingClientRect(), clientWidth,scrollWidth区别
- width、clientWidth、offsetWidth、scrollWidth、availWidth
- scrollWidth,clientWidth,offsetWidth 区别
- clientWidth offsetWidth scrollWidth区别
- offsetWidth scrollwidth clientWidth 区别
- scrollWidth clientWidth offsetWidth style.width screen.width
- scrollWidth() clientWidth() offsetWidth() style.width() screen.height()
- scrollWidth,clientWidth,offsetWidth的区别
- scrollWidth,clientWidth,offsetWidth的区别
- scrollWidth,clientWidth,offsetWidth的区别
- scrollWidth,clientWidth,offsetWidth的区别
- scrollTop,scrollWidth,offsetWidth,clientWidth区别
- scrollWidth,clientWidth,offsetWidth的区别
- clientWidth,scrollWidth,offsetWidth的区别
- offsetwidth,clientwidth,scrollWidth的区别
- scrollWidth,clientWidth,offsetWidth的区别
- scrollWidth,clientWidth,offsetWidth的区别
- scrollWidth、clientWidth、offsetWidth的区别;
- 个人学习总结一机器学习入门(九)
- ajax如何设置同步
- ★★★★★图说C++对象模型:对象内存布局详解
- 224. Basic Calculator
- 文章标题
- 各种width,offsetWidth, getBoundingClientRect(), clientWidth,scrollWidth区别
- 手机扫描识别,扫描名片识别信息
- 2017计蒜之道 第四场 商汤科技的安全令牌
- 【sqlite乱码已解决2017-06】SQLite数据库的乱码解决办法
- 伪目标
- Compile chromium OS on Debian
- python中的ORM
- 找出1到n所有数的因数
- Android Studio——设置代理