当前位置:网站首页>offsetwidth\clientwidth\scrollwidth
offsetwidth\clientwidth\scrollwidth
2022-06-28 16:37:00 【ㄗòs╃牸架】
关于js中的offsetwidth、clientwidth、scrollwidth等一系列属性及其方法一直都傻傻分不清,这里就来总结一下这些方法的用法和含义。
目录
一、clientwidth和clientheigh 、 clienttop和clientleft
二、offsetwidth和offsethight 、 offsettop和offsetleft
三、scrollwidth和scrollheight 、 scrolltop和scrollleft
一、clientwidth和clientheigh 、 clienttop和clientleft
1,clientwidth的实际宽度 clientwidth = width+左右padding
2,clientheigh的实际度 clientheigh = height + 上下padding
3,clienttop的实际宽度 clienttop = boder.top(上边框的宽度)
4,clientleft的实际宽度 clientleft = boder.left(左边框的宽度)
二、offsetwidth和offsethight 、 offsettop和offsetleft
1,offsetwidth的实际宽度
offsetwidth = width + 左右padding + 左右boder
2,offsetheith的实际高度
offsetheith = height + 上下padding + 上下boder
3,offsettop实际宽度
offsettop:当前元素 上边框 外边缘 到 最近的已定位父级(offsetparent) 上边框 内边缘的 距离。如果父级都没有定位,则分别是到body 顶部 和左边的距离
4,offsetleft实际宽度
offsetleft:当前元素 左边框 外边缘 到 最近的已定位父级(offsetparent) 左边框 内边缘的 距离。如果父级都没有定位,则分别是到body 顶部 和左边的距离
三、scrollwidth和scrollheight 、 scrolltop和scrollleft
1,scrollwidth实际宽度
scrollwidth:获取指定标签内容层的真实宽度(可视区域宽度+被隐藏区域宽度)。
2,scrollheight的实际高度
scrollheight:获取指定标签内容层的真实高度(可视区域高度+被隐藏区域高度)
3,scrolltop
scrolltop :内容层顶部 到 可视区域顶部的距离。
4,scrollleft
scrollleft:内容层左端 到 可视区域左端的距离.
注意: 下面元素属性和元素方法都通过 elem.属性 或 elem.方法 的方式使用,window属性通过 window.属性 的方式使用,document属性则通过document调用。
边栏推荐
- 【Laravel】关于Laravel8的composer安装
- 中国SSD行业企业势力全景图
- visio 使用
- O & M - unified gateway is very necessary
- 如何清除 WordPress 中的缓存
- 访中国信通院王蕴韬:数实融合赋能文化产业繁荣发展
- 【TcaplusDB知识库】修改业务修改集群cluster
- Cardinality sorting - common sorting method (2/8)
- What you have to know under the digital collection boom
- 2022年暑期及9月份CSP-J1 CSP-S1初赛 培训计划及学习要点
猜你喜欢
随机推荐
NOIP1998-2018年普及组 CSP-J2 2019 2020 解题报告及视频
Zuckerberg to investors: don't expect anything from metauniverse
一步一步教你制作的第一个 WordPress 插件
大型体育赛事与犯罪风险
【Golang】安装 iris 的方法
WPF video hard decoding, rendering and playing (no airspace) (support 4K, 8K and high frame rate video)
3. Caller 服务调用 - dapr
[redis] a brief summary of redis on January 31, 2021 No.01
中国SSD行业企业势力全景图
NOIP普及组2006-2018初赛 2019 CSP-J1 2020 CSP-J1 完善程序题
The new paradigm of AI landing is "hidden" in the next major upgrade of software infrastructure
[force button] 977 Square of ordered array
Design details of the full stack CRM development tool webclient UI workbench
7-用户输入和while循环
PID control details [easy to understand]
【Hot100】1. Sum of two numbers
【Redis】2021/01/31 Redis的简单归纳 No.01
如何登录到你的 WordPress 管理仪表板
LTspice 电路仿真入门
R 编程语言 - 简介









