Skip to content

Instantly share code, notes, and snippets.

@bmoren
Created November 12, 2016 21:09
Show Gist options
  • Save bmoren/080ce4e89b959287b869222f9af5985d to your computer and use it in GitHub Desktop.
Save bmoren/080ce4e89b959287b869222f9af5985d to your computer and use it in GitHub Desktop.
Mouse not moving
// +~+~+~+~+~ raw jQ/jS +~+~+~+~+~~+
var timeout = null;
$(document).on('mousemove', function() {
clearInterval(timeout);
timeout = setInterval(function() {
console.log('Mouse idle...');
//this is where you put the code to do things...
}, 200); //rate of interval
});
//+~+~+~+~+~+as a Jquery plugin.+~+~+~+~+~+
$.fn.mouseNotMoving = function(returnRate, callback) {
var timeout = null;
$(this).on('mousemove', function() {
clearInterval(timeout);
timeout = setInterval(function() {
// console.log('Mouse idle...');
if(typeof callback == 'function'){ callback() };
}, returnRate); //rate of interval
})
}
//how to use the jQuery plugin.
$(document).mouseNotMoving(200,function(){
console.log("mouse not moving...")
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment