How can I differentiate a manual scroll (via mousewheel/scrollbar) from a Javascript/jQuery scroll?

后端 未结 3 1414
栀梦
栀梦 2020-11-27 04:47

UPDATE:

Here is a jsbin example demonstrating the problem.

UPDATE 2:
And here is the fixed version thanks to fudgey.


Bas

3条回答
  •  情书的邮戳
    2020-11-27 05:24

    Try this function:

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

    Also, did you see this tutorial?

    Update: Modern browsers now use "wheel" as the event, so I've included it in the code above.

提交回复
热议问题