Jquery .animate() stop scrolling when user scrolls manually?

前端 未结 4 519
半阙折子戏
半阙折子戏 2020-12-04 14:21

I have set up a snippet that scrolls a page section into view when it\'s clicked, the problem is that if the user wants to scroll in the middle of the animation the scroll k

4条回答
  •  温柔的废话
    2020-12-04 15:08

    I would do it by detecting user events

    $('body,html').bind('scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove', function (e) {
      if (e.which > 0 || e.type == "mousedown" || e.type == "mousewheel" || e.type == "touchmove") {
        $("html,body").stop();
      }
    });
    

    Here is a good tutorial.

提交回复
热议问题