views:

514

answers:

2

Hi there,

I was looking on this post but it doesn't really help me. What I'm trying to do is to create event, or what would be even better, access current mouse screen coordinates.

I have a function with setTimeout inside it, where number of different checks on attributes are performed. In my program some of the elements are changing position and what I want to do is check whether mouse is still over some elements or not.

Many thanks,

Artur

A: 

You just want to bind to the onmouseover and onmouseout events of an object. I found this to be unreliable however as some users can't keep a cursor over a small target so I found a great plug-in for jQuery called hoverIntent that works beautifully.

CptSkippy
A: 

This solves the problem:

// Mouse coordinates for event.clientX, event.clientY respectively.
var myClientX, myClientY;

// This call makes sure that global variables myClientX, myClientY are up to date
window.document.addEventListener("mousemove", function(event) {
    myClientX = event.clientX;
    myClientY = event.clientY;
}, false);

Making coordinates global let's me access them whenever I want :)

Artur