How to trigger ajax request on scroll stop?

后端 未结 3 1570
星月不相逢
星月不相逢 2021-01-07 04:26

On window scroll I\'m doing ajax request like this

$(window).scroll(function(){
 //doing ajax request
});

but it is creating multiple ajax

3条回答
  •  心在旅途
    2021-01-07 05:03

    I don't believe there's an onscrollstop listener, but you can emulate it by setting a timeout and clearing it if scrolling continues.

    var timeout = null;
    
    $(window).scroll(function() {
        clearTimeout(timeout);
        timeout = setTimeout(function() {
            // do your ajax request
        }, 100);
    });
    

提交回复
热议问题