[Javascript] offsetTop inside a TD (IE 5 and 6)

Muchacho, Laurent (TWIi London) LMuchacho at twii.net
Sun Jan 18 09:55:45 CST 2004


 Hi Peter

I had a similar problem when I try to get the offsettop of an element in IE
I found this function on the net but don't remenber where if the author
recognize himself please claim the credit for this work and give us the url
of your site.

function getAbsX(elt) { return parseInt(elt.x) ? elt.x :
getAbsPos(elt,"Left"); }
function getAbsY(elt) { return parseInt(elt.y) ? elt.y :
getAbsPos(elt,"Top"); }
function getAbsPos(elt,which) {
 iPos = 0;
 while (elt != null) {
  iPos += elt["offset" + which];
  elt = elt.offsetParent;
 }
 return iPos;
}

to get the relative position of an element just call 
the function getAbsY(elt)
ex:
alert(getAbsY(document.getElementById('yourDivId')));

and you will get the position from the top of this element 

Laurent


-----Original Message-----
From: Peter Brunone
To: javascript at latech.edu
Sent: 16/01/2004 21:50
Subject: [Javascript] offsetTop inside a TD (IE 5 and 6)


	This isn't strictly Javascript related, so smack me if you think
I'm too far off-topic.  Also, it's limited to up-level Internet
Explorer, since that's my current development platform.

	I've been summing the offsetTop and offsetHeight of say,
Object1, to position the style.top of Object2 directly below it.  This
works just fine until Object1 is in a table cell.

	When the TD is valign="top", I have no problems.  However, when
the valign is middle or bottom, Object1's distance from the top of the
TD is added to the final style.top value of Object2.  

Here are two mockups of the situation.

***********************************************************
Example A:

---------Top of cell (valign middle)-----------



        Object1 in middle of cell


        Object2 starts right below the bottom (about 1/2 cell-height
below where it should).
---------------- Bottom of cell ---------------


Example B:

---------Top of cell (valign bottom)-----------





        Object1 at bottom of cell
---------------- Bottom of cell ---------------




        Object2 starts down here (almost a full cell-height below
Object1)

**************************************************************

Any thoughts on what this strange valign-related value is?

Regards,

Peter Brunone


_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript


DISCLAIMER - The preceding e-mail message (including any attachments)
contains information that may be confidential, may be protected by the
attorney-client or other applicable privileges, or may constitute non-public
information.  It is intended to be conveyed only to the designated
recipient(s) named above.  If you are not an intended recipient of this
message, or have otherwise received it in error, please notify the sender by
replying to this message and then delete all copies of it from your computer
system.  Any use, dissemination, distribution, or reproduction of this
message by unintended recipients is not authorized and may be unlawful. The
contents of this communication do not necessarily represent the views of
this company.



More information about the Javascript mailing list