javascriptjqueryonepage-scroll

JQuery disable onepage scroll in function


In project I use jquery.onepage.scroll plugin. But when I open the modal window and scroll then page in back scrolling too. I fount 2 places in source file of the plugin:

1)

e(document).bind('mousewheel DOMMouseScroll MozMousePixelScroll', function (t) {
    t.preventDefault();
    var n = t.originalEvent.wheelDelta || -t.originalEvent.detail;
    if (!e('body').hasClass('disabled-onepage-scroll')) u(t, n);
});

2)

e(document).bind('mousewheel DOMMouseScroll MozMousePixelScroll', function (e) {
    e.preventDefault();
    var t = e.originalEvent.wheelDelta || -e.originalEvent.detail;
    u(e, t);
});

If I comment that, then scrolling is disabled, but how can I disable it using a function in another file? For example, I have an event listener for opening a modal window, and when it opens -> scrolling is disabled

myModalEl.addEventListener('shown.bs.modal', function (event) {
    disableOnepageScroll();
});

myModalEl.addEventListener('hidden.bs.modal', function (event) {
    disableOnepageScroll();
});


Solution

  • So, I just add the if statement that verify if body has 'modal-open' class name.

    1)

    e(document).bind('mousewheel DOMMouseScroll MozMousePixelScroll', function (e) {
        e.preventDefault();
        var t = e.originalEvent.wheelDelta || -e.originalEvent.detail;
        if (!$(document.body).hasClass('modal-opened')) {
            u(e, t);
        }
    });

    2)

    e(document).bind('mousewheel DOMMouseScroll MozMousePixelScroll', function (t) {
        t.preventDefault();
        var n = t.originalEvent.wheelDelta || -t.originalEvent.detail;
        if (!$(document.body).hasClass('modal-open')) {
            console.log('AAAAA');
            if (!e('body').hasClass('disabled-onepage-scroll')) u(t, n);
        }
    });