问题
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?
回答1:
Use clearTimeout:
var timer;
$(window).scroll(function(){
if ( timer ) clearTimeout(timer);
timer = setTimeout(function(){
// Make your AJAX request here...
}, 10000);
});
来源:https://stackoverflow.com/questions/10573021/jquery-scroll-with-timeout