Click to See Complete Forum and Search --> : reading XY position of DIV


DaveC426913
05-09-2003, 10:57 AM
I'm trying to place an image (an icon) on top of another image (a map) using DHTML and layers, so that one is relative to the other.

Currently, I place the map using HTML and then start the icon's DIV with an absolute XY offset based on where on the page the map is. But as the page is edited, the map's position will change, so a static XY offset will be useless.

Any suggestion as to how I can:
a] read the absolute XY coords of the map so I can use that as my offset?
or
b] place the icon relative to the map regardless of absolute coords?

Browser-independent solutions are preferred, but IE solution will suffice.

Current sample (http://www.pathcom.com/~davecoll/)

(If there's no map here then it's been moved to the Archive page.)

The JavaScript (http://www.pathcom.com/~davecoll/warchalk/mapcoords.js)


Thanks,

Dave

khalidali63
05-09-2003, 11:08 AM
A child div should by default have X and Y co-ords relative to the parent element,unles specified otherwised.

gil davis
05-09-2003, 11:13 AM
If you place the map inside a DIV positioned relative, you can place another DIV inside as well but positioned absolute, and the absolute position will be in relation to the containing DIV.<div style="position: relative">
<img src="...">
<div style="position: absolute; top: 20px; left: 20px">
<img src="...">
</div>
</div>

DaveC426913
05-09-2003, 11:31 AM
<Whacks forehead>

Talk about not seeing the forest though the trees!