JavaScript How to detect when mousemove has stopped

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);
Answer:1

You could try setting/clearing a timeout solely to detect the end of moving the mouse...

var x;
document.addEventListener('mousemove', function() { 
    if (x) clearTimeout(x); 
    x = setTimeout(startInteractionTimer, 200); 
}, false);

How long you want to wait is up to you. I don't know how long you want to say is "the end of a mousemove"

Example: http://jsfiddle.net/jeffshaver/ZjHD6/

Answer:2

I am a n00b in node, and find util.inherits() very useful, except for the fact that it seems to replace the entire prototype of the original object. For instance: var myClass = function(name){ ...

I am a n00b in node, and find util.inherits() very useful, except for the fact that it seems to replace the entire prototype of the original object. For instance: var myClass = function(name){ ...

I need to set the language_in option on the Closure compiler to prevent the IE8 parse error: ERROR - Parse error. IE8 (and below) will parse trailing commas in array and object literals incorrectly. ...

I need to set the language_in option on the Closure compiler to prevent the IE8 parse error: ERROR - Parse error. IE8 (and below) will parse trailing commas in array and object literals incorrectly. ...

I'm looking to implement a warning if the user attempts to leave the order process before it's completed in any fashion other then of course following the payment button. Something like this: <...

I'm looking to implement a warning if the user attempts to leave the order process before it's completed in any fashion other then of course following the payment button. Something like this: <...

I have a leaflet.js map that has points and linestrings on it that come from an external JSON file. If I add: map.setView(new L.LatLng(0,0), 10); It will centre the map on the latitude and ...

I have a leaflet.js map that has points and linestrings on it that come from an external JSON file. If I add: map.setView(new L.LatLng(0,0), 10); It will centre the map on the latitude and ...