Created
November 12, 2016 21:09
-
-
Save bmoren/080ce4e89b959287b869222f9af5985d to your computer and use it in GitHub Desktop.
Mouse not moving
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// +~+~+~+~+~ 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