views:

89

answers:

3

I'm not quite sure how to describe what I'm looking to do, but I'll do my best.

At the moment I have a parent <div>, with absolutely positioned child <div>s within it, and I'm tracking the mouse pointer location coordinates relative to the element your mouse is over.

At the moment, when I mouse over my child <div>s, I get the mouse location relative to them, but I want the coordinates to be relative the the parent <div> even when mousing over the child elements.

So I basically want the child elements to be visible, but transparent to the mousemove, so I want the mousemove to go straight through to the parent element.

How would I do this? Do I maybe need to somehow make the parent <div> be in the forground but still have the child <div>s show through? or make a transparent <div> overlay just to get the mouse coordinates?

A: 

If you put your event handlers on the parent div, then it'll be what gets the events as they bubble up. As to the positioning issue, it might make your life easier to make your parent div be position: relative. The mouse coordinates in the event are always relative to the window, as far as I know, so you're going to have to do the math anyway. I'm really dumb and I've been able to figure that out in the past through trial and error :)

Pointy
I made my parent div `position:relative` so that I could have my child divs positioned absolutely within it, that's fine.Yes, you're right, if I had my event handler in the containing div rather than the whole page then there wouldn't be any problem with the child divs setting it off. I'd still be curious to know if there's a way of having it as a whole page event but having certain elements in the background or ignored.
Acorn
A: 

you're using event.target (srcElement) in your code, just get rid of that and replace with the div in question.

stereofrog
+1  A: 

Okay, I've worked out a way I can ignore the child elements when I mouse over them.

When getting the target of the event I can just change the target to the parentNode if the className of the target matches something:

if (target.className.toLowerCase() === 'ignoreme') { target = target.parentNode; }

Acorn