[JavaScript] getting position

Laurent Muchacho LaurentM at london.virgin.net
Tue Jun 22 10:26:08 CDT 2004


Hi Chris,

Yes it will work even nested into an other element in IE.
If you interested in NS I never tested it. But I guessed if you want to get
an element who is nested you must do something like that
document.layers['parentid'].document.layers['yourid']
<div id="parented" name="parented">
	<div id="yourid" name="yourid">whatever</div>
</div>

I usually use this function like this.
I have an image somewhere in my html with a name and an id when the document
load I get the left and top of this images and position my div on top of it
or related to it.

the ticker is positioned like this in this page 
http://www.virgin.net/shopping/fathersday/index.html
 

Regards 

Laurent

-----Original Message-----
From: Chris T [mailto:christ at saeweb.com]
Sent: 22 June 2004 16:05
To: [JavaScript List]
Subject: Re: [Javascript] getting position


Does this take into consideration if it's nested within other elements?


----- Original Message ----- 
From: "Laurent Muchacho" <LaurentM at london.virgin.net>
To: "'[JavaScript List]'" <javascript at LaTech.edu>
Sent: Tuesday, June 22, 2004 10:50 AM
Subject: RE: [Javascript] getting position


> Hi,
>
> I think this is what you look for this function will return the absolute
> position of an element when you call the function getAbsX(elt) or
> getAbsY(elt) elt must be
> equal to document.all['yourid'] or document.getElementById('yourid') or
> document.layers['yourid']
> <div id="yourid">whatever</div>
>
> if you want to use this function in ns4 you must put a name as well
> <div id="yourid" name="yourid">whatever</div>
>
>
> 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;
> };
>
> ps : I'm not the author of this function I found the logic on the net a
> while ago I just implemented it to my need.
> ps : this function work really well when
> 1. you use an image with a name and an id
> 2. If you use IE MAC don't write dynamcly your html in the page with
> javascript like document.write('<div id="yourid"
> name="yourid">whatever</div>') the IE browser on the mac will get confuse
> and give you really wrong value from what to expect.
>
>
> -----Original Message-----
> From: Iztok Polanic [mailto:iztokp at amis.net]
> Sent: 22 June 2004 15:35
> To: javascript at LaTech.edu
> Subject: [Javascript] getting position
>
>
> Hi!
>
> I'm wondering how to get a position (x, Y) of an object by its ID. How to
do
> this?
>
>
> Bye,
>
> Iztok
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
>
> This E-mail and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they are
addressed.  If you have received this E-mail in error please notify the
system manager.  This message contains confidential information and is
intended only for the individual named.  If you are not the named addressee
you should not disseminate, distribute or copy this E-mail.
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript

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


This E-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed.  If you have received this E-mail in error please notify the system manager.  This message contains confidential information and is intended only for the individual named.  If you are not the named addressee you should not disseminate, distribute or copy this E-mail.



More information about the Javascript mailing list