.offset().top 与 .offsetTop

1.
$$( popupHeaderElem ).offset() 是jquery的API, 如果计算的结果有小数点,那么显示的结果就是浮点型数据.
它有两个数值, top 和 left , $( popupHeaderElem ).offset().top 和 $( popupHeaderElem ).offset().left
jquery API document 里面说:

The .offset() method allows us to retrieve the current position of an element (specifically its border box, which excludes margins) relative to the document

offset() 函数就是在所有匹配的element 中,找到第一个, 计算相对于document的位置
Description: Get the current coordinates of the first element in the set of matched elements, relative to the document.

注: Document的高度是有可能超出整个window或者浏览器的,假设我们关注的element是div , 并且div本身是没有scrollbar的,那么当窗口出现scrollbar的时候,实际是document本身的,这时滚动scrollbar,div的offset()值不变。

以下两张图片均为转载:

图1
图2

2.
$(popupHeaderElem)[0].offsetTop 是javascript 的计算方式,整型.是相对于offsetParent的距离.

offsetTop returns the distance of the current element relative to the top of the offsetParent node

参考链接

[1]stackoverflow 讨论, 说的很详细
[2]有关.offset()的图片解释

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值