Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Triggering mousemove on the mouse's current position

Tags:

javascript

Suppose we have a <div> with a mousemove handler bound to it. If the mouse pointer enters and moves around this div, the event is triggered.

However, I am dealing with a rich web application where <div>s move around the screen, appear and disappear... So it may happen that a <div> appears under the mouse pointer. In this case, mousemove is not triggered. However, I need it to be. (Note that replacing mousemove with mouseover does not change this behavior.)

Specifically, the <div> has to be highlighted and I deem it as a UI flaw to require the user to do a slight mouse move in order to trigger the highlighting.

Is it possible to trigger the mousemove event programatically? And I do not mean

document.getElementById('mydiv').onmousemove();

because onmousemove is parametrised by the event object, which I do not have.

Is it possible to make browser behave as if onmousemove was triggered on the current mouse's position (although in fact the mouse didn't move)?

like image 551
Imp Avatar asked Jan 16 '23 18:01

Imp


1 Answers

You could modify your mousemove to keep a state variable with the current mouse coordinates, and use that information to perform a collision detection that you call both on mouse move, and on moving a div.

A little example of what that might look like

like image 153
David Hedlund Avatar answered Jan 23 '23 14:01

David Hedlund