How to determine scroll direction without actually scrolling

后端 未结 6 1369
走了就别回头了
走了就别回头了 2020-11-30 02:09

I am coding a page where the first time the user scrolls, it doesn\'t actually scroll the page down, instead it adds a class with a transition. I\'d like to detect when the

6条回答
  •  情书的邮戳
    2020-11-30 03:06

    I know this post is from 5 years ago but I didn't see any good Jquery answer (the .on('mousewheel') doesn't work for me...)

    Simple answer with jquery, and use window instead of body to be sure you are taking scroll event :

    $(window).on('wheel', function(e) {
        var scroll = e.originalEvent.deltaY < 0 ? 'up' : 'down';
        console.log(scroll);
    });
    

提交回复
热议问题