jquery scroll with timeout

风流意气都作罢 提交于 2021-02-19 02:03:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!