Problem with offsetTop and element position location in IE
This is just a small note for someone looking into a similar problem.
I was implementing keyboard navigation with explicit scrolling using scrollTo method, and found out that in IE I cannot get correct values for element position on the page. I use Prototype and it's Position.cumulativeOffset method (which, in turn, uses offetTop/offsetParent properties of the element). Position calculation worked fine in FF, Safari and Opera, but sometimes failed in IE.
The DOM tree I was operating with consisted of several nested UL, LI, SPAN elements (SPAN inside LI).
I added some debug code and found out, that SPAN elements sometimes got huge offset relative to LI, though it should be simply 0 (FF showed value of -1).
The solution to the problem was to add position:relative style to the SPAN, after that the problem disappears.
Unfortunately, I was unable to reproduce the problem with a simple test case to give the example here.
css javascript ie
Labels: CSS, Javascript


8 Comments:
Nice, thanks, that helped me a lot (I had a similar problem in IE).
It's working for me too. Thanks!
Solved a big headache for me too! thanks
Thank you! After much fruitless googling this finally sorted a problem I was having with IE6. I had to add some dummy 'position:relative' style to some TD elements in order to get things to work correctly.
Thanks a lot man it is working
Yes, it helped. Thanks.
Great tip.
Reason 923 to not use Internet Exploder.
Working for me too!
IE has many bugs - no surprise there.
Post a Comment
Links to this post:
Create a Link
<< Home