Scrolling jquery with timeout

I set a timeout with jquery in the scroll action. For example, after scrolling, wait 10 seconds and send an ajax request, but how to undo the previous timeout if you received a new scroll action with the first disconnected disconnected?

+4
source share
1 answer

Use clearTimeout :

 var timer; $(window).scroll(function(){ if ( timer ) clearTimeout(timer); timer = setTimeout(function(){ // Make your AJAX request here... }, 10000); }); 
+13
source

Source: https://habr.com/ru/post/1412266/


All Articles