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

后端 未结 14 741
生来不讨喜
生来不讨喜 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 18:42

    If I understand your question correctly, then you want to prevent scrolling of the main content when the mouse is over a div (let's say a sidebar). For that, the sidebar may not be a child of the scrolling container of the main content (which was the browser window), to prevent the scroll event from bubbling up to its parent.

    This possibly requires some markup changes in the following manner:

    See it's working in this sample fiddle and compare that with this sample fiddle which has a slightly different mouse leave behavior of the sidebar.

    See also scroll only one particular div with browser's main scrollbar.

提交回复
热议问题