Can I declare logic on jQuery for the start and end of a scrolling event?

前端 未结 1 1303
自闭症患者
自闭症患者 2020-12-07 05:00

I would like to setup logic for when the user begins scrolling around the page and after the scrolling is finished, how can I accomplish this?

I want to avoid the be

相关标签:
1条回答
  • 2020-12-07 05:56

    You can try defining you're own debounced events. A (very crude) implementation would look something like this:

    var t, l = (new Date()).getTime();
    
    $(window).scroll(function(){
        var now = (new Date()).getTime();
    
        if(now - l > 400){
            $(this).trigger('scrollStart');
            l = now;
        }
    
        clearTimeout(t);
        t = setTimeout(function(){
            $(window).trigger('scrollEnd');
        }, 300);
    });
    

    See: http://www.jsfiddle.net/yijiang/fGmbe/ for a live demo

    0 讨论(0)
提交回复
热议问题