offsetXXX、scrollXXX 与clientXXX的区别与联系
offsetTop returns the distance of the current element relative to the top of the offsetParent
node.
offsetLeft Returns the number of pixels that the upper left corner of the current element is offset to the left within the offsetParent
node.
offsetHeight returns height of an element relative to the element's offsetParent.
offsetHeight is part of the MSIE's DHTML object model. offsetHeight is not part of any W3C specification or technical recommendation.
offsetHeight is a property of the DHTML object model which was first introduced by MSIE. It is sometimes referred to as an element's physical/graphical dimensions, or an element's border-box height.
offsetParent的理解
MDC中对offsetParent的介绍是这样的:
offsetParent returns a reference to the object which is the closest (nearest in the containment hierarchy) positioned containing element. If the element is non-positioned, the nearest table cell or root element (html in standards compliant mode; body in quirks rendering mode) is the offsetParent. offsetParent returns null when the element has style.display set to "none". The offsetParent is useful because offsetTop and offsetLeft are relative to its padding edge.
在td中的元素会把第一个绝对/相对定位的hierarchy parent当作offsetParent,如果没有找到需要分三种情况讨论
Javascript code:
1.
运行结果:
parentdiv.offsetParent.tagName IS "body"
sondiv.offsetParent.id IS "parentdiv"
2.
运行结果:
parentdiv.offsetParent.tagName IS "body"3.
运行结果:
parentdiv.offsetParent.tagName IS "TD"这个结果是比较有意思的,但它也是符合上面总结的规则的。
4.运行结果:
parentdiv.offsetParent.tagName IS "TD"
sondiv.offsetParent.id IS "TD"
5.
运行结果:
parentdiv.offsetParent.tagName IS "Table"
sondiv.offsetParent.id IS "pareentdiv"
Reference:http://www.cnblogs.com/NRabbit/archive/2009/01/11/1736202.html