Exact Location of an Element

B

Brett Foster

This must have been covered a million times, but I'll be damned if I can
find the right information. Right now I'm using the following code:

This is a function to recusively calculate the absolute position of an
object (because you can't do it directly?):

SomeObject.prototype.__calcOffset__ = function (node) {
if (node && node.offsetTop)
return node.offsetTop + this.__calcOffset__(node.offsetParent);
else
return 0;
}

The problem is that while it worked in a simple layout it's not working
well in other layouts. Any ideas?

Brett
 
F

Fred Oz

Brett said:
This must have been covered a million times, but I'll be damned if I can
find the right information. Right now I'm using the following code:

This is a function to recusively calculate the absolute position of an
object (because you can't do it directly?):

SomeObject.prototype.__calcOffset__ = function (node) {
if (node && node.offsetTop)
return node.offsetTop + this.__calcOffset__(node.offsetParent);
else
return 0;
}

The problem is that while it worked in a simple layout it's not working
well in other layouts. Any ideas?

Brett

Have a look here:

<URL:http://www.quirksmode.org/js/findpos.html>

and play with offsetParent.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top