You’ve probably seen this: you open a popup on your phone, try to scroll inside it, and suddenly the background page starts moving too. It’s distracting and frustrating. Fortunately, there are reliable ways to keep scrolling limited to the popup itself—or to disable background scroll entirely. In this guide, you’ll learn how to do both using CSS (overscroll-behavior) and a bit of jQuery. Let’s make sure your modals feel solid and user-friendly on any device.
HTML Structure
Here’s the basic markup we’ll be working with:
| |
.btntriggers the popup..type_disabledisables background scrolling..pop_wrapis the modal wrapper..popupcontains the content you want scrollable.
CSS Styling
Next, we’ll set up the layout and scroll behavior. Here’s the CSS:
| |
What’s happening here?
.popup_conscrolls on its own without affecting the page behind it..disable_scrolllocks the background by removing all scroll and touch interaction.overscroll-behavior: nonestops scroll chaining to parent elements.
jQuery for Interaction
Here’s the jQuery to control opening and closing the popup:
| |
- Clicking the button fades in the popup.
- If it’s the
.type_disablebutton, the body scroll is locked. - Clicking the background or close button fades the popup out and restores scrolling.
Why Use .disable_scroll?
Applying the .disable_scroll class to the <body> has a few key benefits:
- Completely locks the page while the popup is open.
- Disables touch gestures on mobile (thanks to
touch-action: none). - Keeps the viewport steady, avoiding jumps or unintended scrolls.
Compare: overscroll-behavior vs .disable_scroll
| Feature | overscroll-behavior: none | .disable_scroll |
|---|---|---|
| Stops scroll chaining to background | ✅ Yes — background won’t scroll when reaching popup limits | ✅ Yes — completely prevents scroll from bubbling to body |
| Blocks all interaction with background | ❌ No — user can still tap or scroll outside the popup | ✅ Yes — background is locked, no interaction is possible |
| Optimized for touch gestures | ✅ Yes — allows smooth, native-like scroll inside popup | ❌ No — disables all touch input for background (including scroll) |
Conclusion
If your goal is to keep scrolling limited to a popup area while allowing the page underneath to stay intact, overscroll-behavior is a clean solution. But if you want to fully lock down the background—especially on mobile—then applying .disable_scroll to the body is the way to go.
Think of them as two levels of control:
- Light touch? Use
overscroll-behavior. - Full lock? Use
.disable_scroll.
Choose based on the kind of user experience you’re designing for. And if you’ve got tips or use cases of your own, feel free to share!
