最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
jquery 1.7和1.9的position方法对固定(fixed)元素的区别
时间:2022-06-25 17:43:22 编辑:袖梨 来源:一聚教程网
在jquery的position方法,官方是这样说明的:
Get the current coordinates of the first element in the set of matched elements, relative to the offset parent.The .position() method allows us to retrieve the current position of an element relative to the offset parent. Contrast this with .offset(), which retrieves the current position relative to the document. When positioning a new element near another one and within the same containing DOM element, .position() is the more useful.jQuery does not support getting the position coordinates of hidden elements or accounting for borders, margins, or padding set on the body element.
大致意思是获得匹配元素相对于最近定位父级的距离,返回left、top值。
在CSS中有一个定位属性是比较特殊的,那就是固定属性(fixed),固定元素是相对于文档的,与页面滚动的距离无关。这一点,在jquery的1.9版本之前与1.9版本是有2种不同的解释的。关于这个区别,没有在官方的jquery升级指南里指出来,这里就抛钻引玉一下下啦。
jquery 1.9版本测试:
jquery 1.7版本测试:
您可以拉动滚动条测试,返回的值,只有jquery 1.9是正确的。那么如何在jquery 1.7版本也获得正确的结果呢?使用当前的position.top-window.scrollTop值,即为正确的结果。
相关文章
- 逃离鸭科夫怎么联机 联机方法mod安装教程 11-03
- 二重螺旋水母丽蓓卡怎么玩 水母丽蓓卡玩法攻略分享 11-03
- 逃离鸭科夫实验室防御力场2怎么做 防御力场2任务流程 11-03
- 碧蓝航线反和谐怎么设置 反和谐fhx小开关攻略 11-03
- 燕云十六声不见山前尘旧物怎么收集-不见山前尘旧物全收集攻略 11-03
- 逃离鸭科夫实验室计算中枢怎么完成 计算中枢任务流程 11-03