当前位置: 移动技术网 > IT编程>开发语言>JavaScript > JS中的位置和宽度:clientWidth、offsetWidth、scrollWidth等区别介绍

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

2018年12月11日  | 移动技术网IT编程  | 我要评论

首先定义一个p。

\

然后稍微装修一下

\

下面开始区分

一、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:内容层左端 到 可视区域左端的距离.

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网