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

后端 未结 14 735
生来不讨喜
生来不讨喜 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:02

    You could use a mouseover event on the div to disable the body scrollbar and then a mouseout event to activate it again?

    E.g. The HTML

    content

    And then the javascript like so:

    var body = document.getElementsByTagName('body')[0];
    function disableBodyScroll() {
        body.style.overflowY = 'hidden';
    }
    function enableBodyScroll() {
        body.style.overflowY = 'auto';
    }
    

提交回复
热议问题