How to programmatically disable page scrolling with jQuery

后端 未结 23 2120
滥情空心
滥情空心 2020-11-22 08:09

Using jQuery, I would like to disable scrolling of the body:

My idea is to:

  1. Set body{ overflow: hidden;}
  2. Capture the current
23条回答
  •  醉酒成梦
    2020-11-22 08:39

    You can attach a function to scroll events and prevent its default behaviour.

    var $window = $(window);
    
    $window.on("mousewheel DOMMouseScroll", onMouseWheel);
    
    function onMouseWheel(e) {
        e.preventDefault();
    }
    

    https://jsfiddle.net/22cLw9em/

提交回复
热议问题