理清offsetparent()、offsetLeft/offsetTop、offset()、position()

来源:互联网 发布:linux修改eth0ip命令 编辑:程序博客网 时间:2024/05/29 13:23

简而言之,它们的概念如下:

① offsetparent() 指的是元素的第一级拥有定位属性(absolute/relative/fixed)的父元素。

② offsetLeft/offsetTop 元素boder外侧,到其offsetparent()的border内侧的偏移量。

③ offset() 返回{left:xx, top: yy}, 它表示元素对于文档的绝对偏移量。

④ position() 返回{left:xx, top: yy}, 它表示元素magrin外部,到其offsetparent()的border内侧的距离。

参考资料:
1. offsetparent()的定义:jQuery 遍历 - offsetParent() 方法

2. offset()与position()的区别:Jquery中的offset()和position()深入剖析

原创粉丝点击