[JS] Find the absolute position
Slightly Wonky Robob 19 Oct 2008
This is starting to drive me crazy... all I want to do is find the absolute position of an element, and it is perfectly possible and easy in every browser except IE. Whatever I try 0 is returned. Here is the code that I thiefed off of tinternet:
Anyone got any ideas of how to make this work in IE?
function findPosX(obj) { var curleft = 0; if(obj.offsetParent) while(1) { curleft += obj.offsetLeft; if(!obj.offsetParent) break; obj = obj.offsetParent; } else if(obj.x) curleft += obj.x; return curleft; } function findPosY(obj) { var curtop = 0; if(obj.offsetParent) while(1) { curtop += obj.offsetTop; if(!obj.offsetParent) break; obj = obj.offsetParent; } else if(obj.y) curtop += obj.y; return curtop; }
Anyone got any ideas of how to make this work in IE?
Teron 19 Oct 2008
The only possiblity I see here of returning "0" is when "obj.offsetParent == false" and (obj.x or obj.y) is false.
Does that help?
Does that help?
Slightly Wonky Robob 23 Oct 2008
Well I know/knew that at least one thing was wrong, but the problem is I don't know what the IE equivalent(s) is.
Edited by Bob, 23 October 2008 - 23:38.
Edited by Bob, 23 October 2008 - 23:38.