views:

332

answers:

1

I get different values from Prototype's cumulativeOffset function in Internet Explorer 8 and Firefox 3.5 within a complex layout with several elements having paddings and margins.

This seems to be a known bug: Discussion

Does anybody know a prototype based or prototype compatible method of reliably determining the offset height of a statically positioned element?

+2  A: 

Here's a diagram from Kangax's cheat sheet, who is one of the members of the Prototype DEV team.

alt text

You could add the viewport offset and the scroll offsets, but I'm not sure of this will contain the same issue.

Most of the time I use this Quirksmode script for finding element positions:

function findPos(obj) {
    //find coordinates of a DIV
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft, curtop];
}
Diodeus
The quirksmode script works fine and I think I will be using that. Thanks!
Pekka