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)?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With