What would make offsetParent null?

前端 未结 7 863
清歌不尽
清歌不尽 2020-12-09 17:59

I am trying to do positioning in JavaScript. I am using a cumulative position function based on the classic quirksmode function that sums offsetTop and o

相关标签:
7条回答
  • 2020-12-09 18:43

    I have run into this problem when the sibling just to the left of the element is hidden:

    <div id="parent">
      <div id="element1">some stuff</div>
      <div id="element2" style="display: none">some hidden stuff</div>
      <div id="element3">child whose offset we want</div>
    </div>
    

    I've run into the case where the offsetParent of element3 is null even though element3 itself is visible, and parent is visible.

    I've seen thin is Firefox 3.6 and Chrome 5. It seems to also affect the getBoundingClientRect() function on the element3, which is really annoying since that works in so many other cases!

    0 讨论(0)
提交回复
热议问题