Jump to content

Aligning Div Elements

Guest rjcarr

Recommended Posts

As most things web related, this falls into many categories, but hopefully I've found the right place. I want to be able to dynamically draw "shapes" onto a map using javascript. I've got most everything accomplished except the alignment of the div elements necessary to create the scene.Here are the necessary elements:o an underlying basemap (a png image)o a blank div element placed directly on top of the map to act as the "canvas" for the drawingI've tried many different things and nothing is perfect when trying to accomodate cross-browser correctness (only latest versions of IE and firefox). Here's what I have so far:+ create a parent div for the two inner elements (this can be done in *many* ways)

<div id="parent" style="position:relative">  <img id="map" style="width:391px; height:450px; z-index:1" src="image.png" >  <div id="shapes" style="position:absolute; top:0px; left:0px; width:391px; height:450px; z-index:2"></div>    </div>

+ add mouse handlers for the parent element

document.getElementById("parent").onmousemove = handleMouseMoveMap;if(document.getElementById("parent").captureEvents) {  document.getElementById("parent").captureEvents(Event.MOUSEMOVE);}

+ now, in the handleMouseMoveMap() function, I can check where the mouse is on the map

function handleMouseMoveMap(e) {  if(!e) e = window.event;  ...  var x = e.offsetX; // IE  var x = e.layerX; // FF  ...}

This seems to work admirably in every browser I've tested it with, just wanted to make sure things don't look horribly wrong somehow.Thanks for taking a look.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...