JavaScript: creating an event with current mouse coordinates

I watched this post, but it really doesn’t help me. What I'm trying to do is create an event or, even better, access the current coordinates of the mouse screen.

I have a function with setTimeout inside it, where a number of different attribute checks are performed. In my program, some of the elements change position, and I want to check whether the mouse remains on some elements or not.

Thank you very much,

Arthur

0
source share
2 answers

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); 

Creating global coordinates allows me to access them whenever I want :)

0
source

You just want to bind to the onmouseover and onmouseout events of the object. I found this to be unreliable, however, some users cannot hold the cursor over a small target, so I found a great jQuery plugin called hoverIntent that works great.

0
source

Source: https://habr.com/ru/post/1445401/


All Articles