Detect scrolling attempts in overflow:hidden page?

前端 未结 2 1658
萌比男神i
萌比男神i 2021-01-18 08:18

I want to detect when the user is trying to scroll up or down on my page, but since I don\'t want to allow the actual scrolling I have set an overflow:hidden body. The code

相关标签:
2条回答
  • 2021-01-18 08:42

    Try using jQuery mousewheel https://github.com/brandonaaron/jquery-mousewheel. You can detect the mousewheel movement. The other option is to not set the overflow to hidden but instead catch the scroll attempt and scroll them yourself. There are also a bunch of libraries for JS scrolling, I like http://manos.malihu.gr/jquery-custom-content-scroller/.

    0 讨论(0)
  • 2021-01-18 09:01

    Here's a jQuery-solution.

    $(document).bind('mousewheel', function(e) {
        var delta = e.originalEvent.wheelDelta;
        console.log('The mouse delta is : ' + delta);
    });
    

    jQuery Doc - .bind()

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