Link to home
Start Free TrialLog in
Avatar of WebDvlp
WebDvlp

asked on

Show mouse position in DIV

I have set an onmousemove event on a DIV in which I want to locate
the position of the mouse cursor (relative to the top left of the DIV). I am using
event.offsetX and event.offsetY to get the position of the mouse within the
DIV element. This works great, as long as there is no object inside the DIV. When I
add an image in the DIV, as soon as the cursor passes over that image,
offsetX and Y become 0 again.

How can I get the event.offsetX and event.offsetY to always be reported in
relation to my parent DIV element?
Avatar of lherrou
lherrou
Flag of Ukraine image

WebDvlp,

How about placing the object in a DIV of it's own, and then overlay your mouse recording DIV over the top of that?

Cheers,
LHerrou
Avatar of WebDvlp
WebDvlp

ASKER

Pfffffew... there must be an easier solution... I don't know how many and what kind of elements there will be in the DIV.
Maybe I should ask what you're doing with the cursor position information once you have it... it's tied to the content in the DIV?

Avatar of WebDvlp

ASKER

I just want to know on which position the cursor is in the div, relative to the top and left of the div. This works file with offsetx and offsety, but not when there are elements inside the container div.
Then an overlay should work fine. Just layout your page, and then put a new, transparent layer over the whole thing and get your mouse position in that one.
Avatar of WebDvlp

ASKER

Do you have some cross browsr code?
ASKER CERTIFIED SOLUTION
Avatar of lherrou
lherrou
Flag of Ukraine image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial