Scrolling child div scrolls the window, how do I stop that?

后端 未结 14 753
生来不讨喜
生来不讨喜 2020-11-30 18:03

I have a div, with a scroll bar, When it reaches the end, my page starts scrolling. Is there anyway I can stop this behavior ?

14条回答
  •  没有蜡笔的小新
    2020-11-30 19:05

    this disables the scrolling on the window if you enter the selector element. works like charms.

    elements = $(".selector");
    
    elements.on('mouseenter', function() {
        window.currentScrollTop = $(window).scrollTop();
        window.currentScrollLeft = $(window).scrollTop();
        $(window).on("scroll.prevent", function() {
            $(window).scrollTop(window.currentScrollTop);
            $(window).scrollLeft(window.currentScrollLeft);
        });
    });
    
    elements.on('mouseleave', function() {
        $(window).off("scroll.prevent");
    });
    

提交回复
热议问题