?
Solved

Show mouse position in DIV

Posted on 2006-04-20
9
Medium Priority
?
158 Views
Last Modified: 2010-04-09
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?
0
Comment
Question by:WebDvlp
  • 4
  • 3
7 Comments
 
LVL 38

Expert Comment

by:lherrou
ID: 16500311
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
0
 

Author Comment

by:WebDvlp
ID: 16500425
Pfffffew... there must be an easier solution... I don't know how many and what kind of elements there will be in the DIV.
0
 
LVL 38

Expert Comment

by:lherrou
ID: 16500576
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?

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:WebDvlp
ID: 16500744
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.
0
 
LVL 38

Expert Comment

by:lherrou
ID: 16500794
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.
0
 

Author Comment

by:WebDvlp
ID: 16501029
Do you have some cross browsr code?
0
 
LVL 38

Accepted Solution

by:
lherrou earned 2000 total points
ID: 16525460
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article discusses four methods for overlaying images in a container on a web page
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question