Scroll event firing too many times. I only want it to fire a maximum of, say, once per second

后端 未结 8 750
再見小時候
再見小時候 2020-11-27 12:24

I have a page with \"infinite scroll\". It calculates the difference between the end of the page and the current page and loads more content if this difference is small enou

8条回答
  •  一向
    一向 (楼主)
    2020-11-27 12:46

    var isWorking = 0;
    
    $(window).on('scroll', function()
    {
        if(isWorking==0)  
        {
             isWorking=1;
             if (window.pageYOffset > loadMoreButton.offsetTop - 1000)
             # load more content via ajax
             setTimeout(function(){isWorking=0},1000);
        }
    }
    

提交回复
热议问题