How to prevent body scrolling but allow overlay scrolling?

How to prevent body scrolling but allow overlay scrolling?

Generally speaking, if you want a parent (the body in this case) to prevent it from scrolling when a child (the overlay in this case) scrolls, then make the child a sibling of the parent to prevent the scroll event from bubbling up to the parent. In case of the parent being the body, this requires an additional wrapping element:

How to prevent page scrolling when a modal is open?

We can use JavaScript to avoid the touch event bubble. We all know there should be a backdrop layer when a modal is open. Unfortunately, stopPropagation is a little awkward with touch in iOS. But preventDefault works well.

How to disable scroll chaining in CSS?

The behaviour you want to prevent is called scroll chaining. To disable it, set on your overlay in CSS. You can easily do this with some “new” css and JQuery.

How to prevent the body from scrolling on Pinterest?

Looking at current implementation of the pinterest site (it might change in the future), when you open the overlay a noscroll class is applied to the body element and overflow: hidden is set, thus body is no longer scrollable.

How are scroll panes used to save space?

Other containers used to save screen space include split panes and tabbed panes. The code to create a scroll pane can be minimal. For example, here’s a picture of a demo program that puts a text area in a scroll pane because the text area’s size grows dynamically as text is appended to it:

How is the behavior of the scroll bar controlled?

This behavior is controlled by the scroll pane’s scroll bar policy, Actually, it’s two policies: each scroll bar has its own. ScrollDemo doesn’t explicitly set the scroll pane’s scroll bar policies — it uses the default. You can set the policies when you create the scroll pane or change them dynamically.

How to use a scroll pane in jscrollpane?

Note that JScrollPane has no corresponding getViewportView method. If you need to refer to the client object again, you can either cache it in a variable or invoke getViewport ().getViewportView () on the scroll pane. When the user manipulates the scroll bars in a scroll pane, the area of the client that is visible changes accordingly.