Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

DHTML Images relative positions

I have a page that contains a map image.

On top of this map image I wish to float another graphicor multiple graphics to show the position of an event. I can happily place one image on top of the other but I cannot gurantee the position of the map on the page so I need to position the floating graphic relative to the position of the map.

So..
How do I find the current position of the map?
How can I then use this to position the image(s) relative to the map?
0
bigprop
Asked:
bigprop
1 Solution
 
brigmarCommented:
Andrew,

You need to put all the images inside a container, and make the positions relative to that container.
The container should be the same size (in pixels) as the map.

<html>
 <body>
 blah BEFORE blah
 <div id="container" style="position:relative; height:400; width:200;">
  <div id="map" style="position:absolute; left:0; top:0;"><img src="map.gif" height="400" width="200"></div>
  <div id="img1" style="position:absolute; left:15; top:15;"><img src="beacon.gif" width="10" height="10"></div>
  <div id="img2" style="position:absolute; left:55; top:55;"><img src="beacon.gif" width="10" height="10"></div>
  <div id="img3" style="position:absolute; left:55; top:15;"><img src="beacon.gif" width="10" height="10"></div>
  <div id="img4" style="position:absolute; left:15; top:55;"><img src="beacon.gif" width="10" height="10"></div>
 </div>
 blah AFTER blah
 </body>
</html>

You can also specify the z-index, but this is unnecessary in this case, as the browser will put elements defined earlier behind the elements defined later.

Good Luck,

Brian
0
 
bigpropAuthor Commented:
Thanks Brian

It works a treat. In fact I found that I didn't have to put the images into their own divs merely have them in the container div.

Keep in touch

Andrew
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now