IE8 is giving me a negative offsetTop when trying to determine the position of an element.
- I've been using a function that gets the position of an element in order to place a floating, absolutely-positioned element underneath the element was clicked - your standard popup menu. The function works by using the offsetTop and offsetLeft of the clicked element then working it's way up the DOM tree using the offsetParent property (code to follow). Within the last week or two, IE8 started showing the popup in the wrong place when scrolling. I traced through it in the debugger and this is due to the offsetTop being set to a negative number for one of the parent <div>s. It's not absolutely positioned nor is anything else in the positioning tree though the element I'm trying to get the position of is inside a <div> that scrolls due to an overflow: auto. The <body> doesn't scroll.
Is anyone else experiencing the same behavior? Is there a solution? My own browser doesn't experience this problem, nor does a few of my coworkers, but a few of my other co-workers have the problem with Vista and IE8. IE8 compatibility mode works fine, but I don't want compatibility mode in general.function GetPosition(Element, InRelationTo) {///<summary>Gets the position of the element. Assumes InRelationTo is positioned and you want the absolute position of Element within InRelationTo.</summary>. var result = new Object(), x = 0, y = 0, sx = 0, sy = 0; if(!InRelationTo) InRelationTo = document.body; var first = true, op, tsx, tsy; while(Element && Element != InRelationTo) { x += Element.offsetLeft; y += Element.offsetTop; if(first) first = false; else { if(Element.scrollTop > 0) sy += Element.scrollTop; if(Element.scrollLeft > 0) sx += Element.scrollLeft; } op = Element.offsetParent; if(op && (Element = Element.parentNode) != op) { tsx = 0; tsy = 0; while(Element && Element != op) { tsy += Element.scrollTop; tsx += Element.scrollLeft; Element = Element.parentNode; } if(Element == op) { sy += tsy; sx += tsx; } } Element = op; } if(Element != InRelationTo && InRelationTo != document.body) { var pos = GetPosition(InRelationTo); x -= pos.x - InRelationTo.scrollLeft; y -= pos.y - InRelationTo.scrollTop; } result.x = x - sx; result.y = y - sy; result.scrollX = sx; result.scrollY = sy; return result; }
Answers
- An update correcting this issue is now available: http://support.microsoft.com/kb/976749.
- Marked As Answer byAlan Waiss Tuesday, November 10, 2009 5:14 PM
All Replies
- We are observing a similar issue. It appears that it's got broken in the October's security patch (KB974455).
- This has really helped me out.
I'm scrolling a div to an element within and works in all browsers including IE7 but not IE8.
offsettop is returning the wrong value.
I hope this gets fixed asap or yet more code needed to display differently for just IE8. Microsoft sent out another update this morning:-
Update for Internet Explorer 8 Compatibility View List for Windows Vista (KB975364)
28/10/2009This compatibility View List update helps make Web sites that are designed for older browsers look better in Internet Explorer 8. When users install Internet Explorer 8, they will be given a choice about opt-in to a list of sites that should be displayed in Compatibility View. After you install this item, you may have to restart Internet Explorer.
More information:
http://go.microsoft.com/fwlink/?LinkID=139381Help and Support:
http://support.microsoft.com/?kbid=975364
This has not resolved this previous bug created by the last update.
I'm going to wind back my updates until I find the exact point at which the bug appears and report back.
BUT
Is this the correct place to report bugs? Does anyone of importance read these?- It does seem to be related to KB974455. After uninstalling that patch, the behavior is corrected and the position is returned correctly.
- Your right it is KB974455.
It's a big update with a "3 stage" shutdown on removal and "3 stage" reboot.
I've sent in a report to microsoft but heard nothing, didn't really expect to though :( - Bug was reported and microsft have assured me it's been registered and being looked.
We'll see. - An update correcting this issue is now available: http://support.microsoft.com/kb/976749.
- Marked As Answer byAlan Waiss Tuesday, November 10, 2009 5:14 PM
- I second that, works for me.
I must admit it's nice to see a quick response from Microsoft and have the feeling your being listened to.


