(function() { var startTime = new Date().getTime(); function timer() { console.log(true); }; document.body.onmousemove = function() { var time = new Date().getTime(); if(time - startTime >= 300) { startTime = time; timer(); } }; })();