Mouse over

E

egebamyasi

I have been trying to find the mouse coords when I move the pointer
over a div/image/etc... When I try e.clientX, e.clientY I retrieve the
mouse coords relative to the browser window. This is okay but
unfortunately when I scroll down the contents change position while the
coords stay the same. Is there any way around this?
 
I

Ivo

egebamyasi said:
I have been trying to find the mouse coords when I move the pointer
over a div/image/etc... When I try e.clientX, e.clientY I retrieve the
mouse coords relative to the browser window. This is okay but
unfortunately when I scroll down the contents change position while the
coords stay the same. Is there any way around this?

So measure the amount that has been scrolled and substract that from the
mousepositions as found. It is unfortunate but will come as no big surprise
that browsers report this in different properties. Some use
document.pageXOffset and document.pageYOffset but IE cs. put the numbers in
document.scrollLeft and document.scrollTop. To see if either a number use
the typeof operator instead of just checking the value because the value may
be 0 (zero).
HTH
Ivo
http://4umi.com/web/javascript/mouseposition.htm
 

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

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top