84669 人学习
152542 人学习
20005 人学习
5487 人学习
7821 人学习
359900 人学习
3350 人学习
180660 人学习
48569 人学习
18603 人学习
40936 人学习
1549 人学习
1183 人学习
32909 人学习
jquery中offsetTop和offset().top什么区别?谢谢
闭关修行中......
http://stackoverflow.com/questions/6777506/offsettop-vs-jquery-offset-top 有解答
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()方法获取
offset();
offsetParent()
http://stackoverflow.com/questions/6777506/offsettop-vs-jquery-offset-top 有解答
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()
方法获取