📜  jquery 检查滚动方向 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:58.208000             🧑  作者: Mango

代码示例1
let scrollDirection = '';
let scrollTopPosition = 0;
$(window).on('scroll', function() {
    if(scrollTopPosition > $(window).scrollTop()) {
        scrollDirection = 'to-top';
    } else {
        scrollDirection = 'to-bottom';
    }
    
    scrollTopPosition = $(window).scrollTop();
});

console.log(scrollDirection);