I set up timeout with jquery at scroll action. For example, after scroll wait 10 seconds and send ajax request, but how to cancel previous timeout if receive new action of scroll withing first timeout not processed?
Use clearTimeout
:
var timer;
$(window).scroll(function(){
if ( timer ) clearTimeout(timer);
timer = setTimeout(function(){
// Make your AJAX request here...
}, 10000);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With