cursor coordinates relavtive to div

G

Guest

hey all,
i'm using a mouseover event for my div and i was wondering how to get the
coordinates of the cursor relative to my DIV. For instance the top left
corner of my div, no matter where on the screen it is, is 0,0?

thanks,
rodchar
 
M

Mike Placentra II

You need to use JavaScript to find the mouse's coordinates. It's a bit
of a mess because of the differences between how browsers give you
cursor coordinates in JavaScript. I would suggest searching something
like "JavaScript cursor coordinates" in a search engine because there
are many resources and code examples on the internet, and it would be
better to find out from there than from me giving you a short example
that might not work perfectly. One example might not cover all
browsers or different versions of browsers, and I'm not too clear on
which browsers use what (for getting mouse coordinates).

These examples generally will give you coordinates relative to the
document, not relative to the <div>. You can calculate the location
relative to the <div> by difference of location of the <div> using
other JavaScript things. That's also messy because different browsers
give you the calculated locations of elements in different ways too.

If you don't get enough information that way and from others who
reply, you can give it a shot in comp.lang.javascript .

-Michael Placentra II
 
G

Guest

thank you for the help.
rod.

Mike Placentra II said:
You need to use JavaScript to find the mouse's coordinates. It's a bit
of a mess because of the differences between how browsers give you
cursor coordinates in JavaScript. I would suggest searching something
like "JavaScript cursor coordinates" in a search engine because there
are many resources and code examples on the internet, and it would be
better to find out from there than from me giving you a short example
that might not work perfectly. One example might not cover all
browsers or different versions of browsers, and I'm not too clear on
which browsers use what (for getting mouse coordinates).

These examples generally will give you coordinates relative to the
document, not relative to the <div>. You can calculate the location
relative to the <div> by difference of location of the <div> using
other JavaScript things. That's also messy because different browsers
give you the calculated locations of elements in different ways too.

If you don't get enough information that way and from others who
reply, you can give it a shot in comp.lang.javascript .

-Michael Placentra II
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top