JS中的位置和宽度:clientWidth、offsetWidth、scrollWidth等区别

1、client

clientWidth: width + 左右padding。

clientHeight: height + 上下padding。

clientTop: 上边框的厚度。

clientLeft: 左边框的厚度。

2、offset

offsetWidth: width + 左右padding + 左右border。

offsetHeight: height + 上下padding + 上下border。

offsetTop: 当前元素上边框外边缘到最近的已定位父级(offsetParent) 上边框内边缘的距离。如果父级都没有定位,则分别是到body顶部的距离。

offsetLeft: 当前元素左边框边缘到最近的已定位父级(offsetParent)左边框内边缘的距离。如果父级都没有定位,则分别是到body左边的距离。

3、scroll

scrollWidth: 获取指定标签内容层的真实宽度(可视区域宽度+被隐藏区域宽度)。

scrollHeight: 获取指定标签内容层的真实高度(可视区域高度+被隐藏语气高度)。

scrollTop: 内容层顶部到可视区域顶部的距离(被隐藏区域宽度)。

scrollLeft: 内容层左边到可视区域左边的距离(被隐藏区域宽度)。

原文地址:https://www.cnblogs.com/huen2015/p/11050765.html