jQuery禁用并启用滚动

Tar*_*ych 7 jquery scroll

$('.news-wrap').mouseenter(function(event) {
    $(window).mousewheel(function(event) {
        event.preventDefault();
    });
});
Run Code Online (Sandbox Code Playgroud)

窗口滚动被禁用,每个我都离开元素.如何使用mouseleave事件启用滚动?

Jos*_*son 9

我写了一个jQuery插件来处理这个问题:$ .disablescroll.

它停止从鼠标滚轮,触摸移动和按钮等滚动Page Down.

$('.news-wrap').mouseenter(function() {

    $(window).disablescroll();

}).mouseleave(function() {

    $(window).disablescroll("undo");

});
Run Code Online (Sandbox Code Playgroud)

希望有人觉得这很有帮助.


jus*_*ric 7

像这样?

$('#abs').bind('mousewheel DOMMouseScroll', function(e) {
    var scrollTo = null;
    if (e.type == 'mousewheel') {
        scrollTo = (e.originalEvent.wheelDelta * -1);
    } else if (e.type == 'DOMMouseScroll') {
        scrollTo = 1000 * e.originalEvent.detail;
    }

    if (scrollTo) {
        e.preventDefault();
        $(this).scrollTop(scrollTo + $(this).scrollTop());
    }
});?
Run Code Online (Sandbox Code Playgroud)