javascript - Difference between offsetParent and parentElement or parentNode -


i have following dom structure

<body>     <div>        <table>           <outerelement>               <innerelement />             </outerelement>        <table>     </div> </body> 

div has it's overflow set auto if table grows bigger - scrolls within div.

in scenario why table.offsetparent returns body while both table.parentnode , parentelement return div?

i need calculate current position of innerelement within window, traverse thru parent elements, collecting offsettop , offsetleft values. until div offsetparent works fine , skips directly body. problem if there's scrolling involved @ point, need account scrolltop , scrollleft - in div in above example. problem if use offsetparent never encounter div 1 of parents.

update

this part of code traversing:

while (oelem && getstyle(oelem, 'position') != 'absolute' && getstyle(oelem, 'position') != 'relative') {     curleft += oelem.offsetleft;    curtop += oelem.offsettop;    oelem = oelem.offsetparent; } 

where getstyle custom function in case retrieves position style.

stay clear of offsetparent, you'll have add lots of hacks , checks ensure right.

try using getboundingclientrect instead.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -