Layer Positioning

G

Guest

Thank you in advance.
I have a table with a <DIV> in it and would like to get the left
property of the <DIV>. It comes back 0. I would like to get the the
position relative to the screen (like 354). Is this possible? If so
could you please point me in the right direction?

Thanks

<TABLE ALIGN="center">
<TR>
<TD>
<DIV>Some Text</DIV>
</TD>
</TR>
</TABLE>
 
D

Dylan Parry

Pondering the eternal question of "Hobnobs or Rich Tea?",
(e-mail address removed) finally proclaimed:
I have a table with a <DIV> in it and would like to get the left
property of the <DIV>. It comes back 0. I would like to get the the
position relative to the screen (like 354). Is this possible? If so
could you please point me in the right direction?

I found the following functions somewhere a while ago:

/*
Function to find the x position of the top left corner of
a given object
*/
function findPosX(obj) {
var curleft = 0;
if (obj.offsetParent) {
while (obj.offsetParent) {
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
}
else if (obj.x)
curleft += obj.x;
return curleft;
}

/*
Function to find the y position of the top left corner of
a given object
*/
function findPosY(obj) {
var curtop = 0;
if (obj.offsetParent) {
while (obj.offsetParent) {
curtop += obj.offsetTop
obj = obj.offsetParent;
}
}
else if (obj.y)
curtop += obj.y;
return curtop;
}

I'm sure they can be improved upon, but they've done the job for me on
many occasions!
 

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

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top