Detecting mousemove with jquery

Is there any way to detect when the mouse stopped moving in jquery?

+3
source share
2 answers

Yes, use setTimeout and clear it every time you move the mouse. If the mouse has not been moved within the time specified in setTimeout, you can assume that the mouse has stopped moving. Using jQuery, you can do something like this:

var stop_timeout = false;
$(function() {
    $().mousemove(function() {
        clearTimeout(stop_timeout);
        stop_timeout = setTimeout(function() {
            alert("The mouse has stopped.");
        }, 1000);            
    });
});

It's a bit hard to set and disable timeouts every time the mouse moves, but it should work for your purposes.

+4
source

hoverintent, . , , ( "-" -).

.

$( selector ).hover( ... )

$( selector ).hoverIntent( ... )

http://cherne.net/brian/resources/jquery.hoverIntent.html

+1

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


All Articles