当前位置:网站首页>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调用。
边栏推荐
- Use open connector to integrate hubspot and SAP systems
- 【力扣】977. 有序数组的平方
- Must the database primary key be self incremented? What scenarios do not suggest self augmentation? ByteDance experience sharing using Flink state 𞓜 afternoon tea with sauce issue 16
- 中国SSD行业企业势力全景图
- STM32CubeMX使用方法及功能介绍
- 高并发、高可用、弹性扩展,天翼云护航企业云上业务
- Design details of the full stack CRM development tool webclient UI workbench
- 岛屿类问题通用解法与DFS框架
- 2022年暑期及9月份CSP-J1 CSP-S1初赛 培训计划及学习要点
- 如何备份 WordPress 数据库
猜你喜欢

AI落地的新范式,就“藏”在下一场软件基础设施的重大升级里

On the design principle of price discount in SAP software

10.hystrix circuit breaker

岛屿类问题通用解法与DFS框架

LTspice 电路仿真入门

Cloud sports, 360 ° witnessing speed and passion

【Hot100】4. Find the median of two positive arrays

【Golang】安装 iris 的方法

【Hot100】1. 两数之和
![[tcapulusdb knowledge base] tcapulusdb technical support introduction](/img/ae/9295c8ae642cde632d06966c28d342.png)
[tcapulusdb knowledge base] tcapulusdb technical support introduction
随机推荐
From five capabilities to "1+5+n", Huawei makes the transformation of government and enterprises more stable
【力扣】977. 有序数组的平方
China energy integration and Tianyi cloud create an "energy brain"
js中订阅发布模式bus
10.Hystrix断路器
The future of platform as code is kubernetes extension
如何让你的 WordPress 网站更安全
中能融合携手天翼云打造“能源大脑”
如何登录到你的 WordPress 管理仪表板
ICML 2022 | 基于解耦梯度优化的可迁移模仿学习方法
大促场景下,如何做好网关高可用防护
QQ出现大规模盗号,为什么会这样?就没有解决方法了吗?
With high concurrency, high availability and elastic expansion, Tianyi cloud escorts Enterprise Cloud business
【Redis】2021/01/31 Redis的简单归纳 No.01
Kiss in the metauniverse! CMU launched VR head display plug-in, reproducing the vivid touch of lips
7-用户输入和while循环
Convolutional neural network for machine learning uses cifar10 data set and alexnet network model to train classification model, install labelimg, and report error
CODING DevOps 助力中化信息打造新一代研效平台,驱动“线上中化”新未来
高并发、高可用、弹性扩展,天翼云护航企业云上业务
【杂谈】2021/01/31 哦豁