doubleyong
管理员
管理员
  • 最后登录2026-05-25
  • 发帖数1198
  • 最爱沙发
  • 喜欢达人
  • 原创写手
  • 社区居民
  • 忠实会员
阅读:9345回复:0

offsetTop vs. jQuery.offset().top

楼主#
更多 发布于:2017-07-24 16:56
This is what jQuery API Doc says about .offset():
Get the current coordinates of the first element, or set the
  coordinates of every element, in the set of matched elements, relative
  to the document.

This is what MDN Web API says about .offsetTop:
offsetTop returns the distance of the current element relative to the
  top of the offsetParent node
中文解析:
1) offset();方法获取的元素相对于当前document元素的位置,可以将其理解为一个绝对位置
2) offsetTop为一个元素相对于器offsetParent的top位置。
3) offsetParent为元素的中距离其最近的一个父元素,这个父元素的position属性为absolute或relative的
4) offsetParent可以通过jQuery的offsetParent()方法获取


参考: https://segmentfault.com/q/1010000004008740
           https://stackoverflow.com/questions/6777506/offsettop-vs-jquery-offset-top
          
知识需要管理,知识需要分享
游客


返回顶部

公众号

公众号