ModernDesigner ModernDesigner - 2 years ago 147
Javascript Question

jQuery - detect if the mouse is still?

I was wondering if there was a way to detect if the mouse is idle for like 3 seconds in jQuery. Is there a plugin that I am unaware of? Because I don't believe there to be a native jQuery method. Any help would be much appreciated!

Answer Source

You can listen to the mousemove event, start a timeout whenever it occurs and cancel any existing timeout.

var timeout = null;

$(document).on('mousemove', function() {

    timeout = setTimeout(function() {
        console.log('Mouse idle for 3 sec');
    }, 3000);


This can be very easily done without jQuery as well (only binding the event handler here is jQuery-specific).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download