How to call a function after scroll has ended?

后端 未结 4 935
渐次进展
渐次进展 2021-01-14 17:30

I want to call a function right after a scroll ends. I have tried a load of different things, none of which have quite worked, and then I came upon this solution in

4条回答
  •  北荒
    北荒 (楼主)
    2021-01-14 18:02

    The jQuery throttle/debounce plugin is perfect for this. Use at_begin = false to execute the callback at the end.

    var scrollEnded = $.debounce(500, false, function ()
    {
        console.log('scroll ended');
    });
    
    $('#scrollableDiv').scroll(scrollEnded);
    

    Demo

提交回复
热议问题