How is it possible to detect with an eventListener when mousemove
has finished?
document.AddEventListener('mousemove', startInteractionTimer, false); function startInteractionTimer(){ clearInterval(touchInterval); touchInterval = setInterval(noAction, 6000); }
I want to start the function startInteractionTimer
immediately after the mousemove has ended and I would like to catch that. On the code example above, it is starting if the mouse is moved.
Thanks
Edit: Alright, I answered my own question and the script above --^ is just fine.
You can simply use the CSS :hover pseudo-class selector in combination with the jQuery mousemove() to check whether the mouse is over an element or not in jQuery.
The MouseMove event is a bubbling event.
MouseMove is a simple event that is executed when a pointer is moving over or around an element. Mousemove is a javascript event that inside a web page. The mousemove event can also be understood as a part of an event handler, whereupon some action or movement by a mouse pointer, an intended script is executed.
You could always make a custom event for it:
(function ($) { var timeout; $(document).on('mousemove', function (event) { if (timeout !== undefined) { window.clearTimeout(timeout); } timeout = window.setTimeout(function () { // trigger the new event on event.target, so that it can bubble appropriately $(event.target).trigger('mousemoveend'); }, 100); }); }(jQuery));
Now you can just do this:
$('#my-el').on('mousemoveend', function () { ... });
Edit:
Also, for consistency with other jQuery events:
(function ($) { $.fn.mousemoveend = function (cb) { return this.on('mousemoveend', cb); }); }(jQuery));
Now you can:
$('#my-el').mousemoveend(fn);
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