Is it possible to somehow force the function to start if the user does not move the mouse for 5 seconds? There is a hidden div with animation, it is necessary that it does not appear immediately when the page is loaded, or not just after 5 seconds, namely when the mouse cursor is 5 seconds long.

At the same time, if he moves the mouse, then the timer is discarded and starts counting only when the cursor again stops.

  • four
    Of course you can! :) - iKuzko
  • one
    As an option to make a timer and when the rodent is active, reset it + check for a timer as soon as it exceeds the threshold value to show a divnik. I myself did not do anything like that in a pure fantasy. - zenith
  • Yes, you yourself know everything :) What are you asking stupid questions for? - zenith
  • zenith, don't be nervous - new_user_1
  • @ new_user_1 Calm like an elephant. Marble - zenith 10:06 pm

3 answers 3

$('#hideDiv').hide(); // прячим необходимый див var showDiv = function(){ $('#hideDiv').show(); }; // функция для его отображения, будет стоять на таймере var timeOut = setTimeout(showDiv, 3000); // ожидание показывания дива $('body').mousemove(function(){ clearTimeout(timeOut); // если дёрнули мышкой обнулили ожидание $('#hideDiv').hide(); // спрятали див timeOut = setTimeout(showDiv, 3000); // начали ждать снова }); 

proof

UPD: update from comrade. @neoascetic

 function showHidenBlock(){ this.timeout = null; this.showBlock = function(){ $('#myHidenBlock').show(); }; this.resetTimeout = function(){ clearTimeout(this.timeout); this.timeout = setTimeout(this.showBlock, 5000); } } var showHidenBlock = new showHidenBlock(); $(window).on({ mousemove:function(){showHidenBlock.resetTimeout()} }); 

As a solution. But next time it is advisable to ask a question more accurately :)

    Here is a handy jquery plugin for your purpose: jquery-idletimer-plugin

    DEMO