How to determine scroll direction without actually scrolling

后端 未结 6 1368
走了就别回头了
走了就别回头了 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 02:55

    Try This using addEventListener.

    window.addEventListener('mousewheel', function(e){
        wDelta = e.wheelDelta < 0 ? 'down' : 'up';
        console.log(wDelta);
    });
    

    Demo

    Update:

    As mentioned in one of the answers, the mousewheel event is depreciated. You should use the wheel event instead.

提交回复
热议问题