Jump to content


[JS] Find the absolute position


2 replies to this topic

#1 Slightly Wonky Robob

    Not a Wonky Gent.

  • Administrator
  • 9337 posts

Posted 19 October 2008 - 13:45

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:

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?
Posted Image
F O R T H E N S
Posted Image

#2 Teron

    Absinth drinker

  • Member
  • 938 posts

Posted 19 October 2008 - 16:52

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?
"It's not the cards you have, it's how you play them!" - Gambit (X-Men)

#3 Slightly Wonky Robob

    Not a Wonky Gent.

  • Administrator
  • 9337 posts

Posted 23 October 2008 - 23:38

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.

Posted Image
F O R T H E N S
Posted Image



2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users