禁用使用jQuery向下滚动

Gen*_*tto 3 javascript jquery scroll

有没有办法只在jQuery中禁用向下滚动?

非常感谢你提前

Ale*_*lex 5

$('html, body').bind('DOMMouseScroll mousewheel MozMousePixelScroll', function(e) {
    var scrollTo = 0;

  if (e.type == 'mousewheel') {
      scrollTo = (e.originalEvent.wheelDelta * -1);
  }
  else if (e.type == 'DOMMouseScroll') {
      // scrollTo = 20 * e.originalEvent.detail; // turns out, this sometimes works better as expected...
      scrollTo = e.originalEvent.detail;
  }

  if (scrollTo > 0) {
    e.preventDefault();
    return false;
  }
});
Run Code Online (Sandbox Code Playgroud)

在这里,你有一个工作小提琴