Skip to content
Advertisement

Simple overlay – prevent background content scrolling

I’ve created a very simple overlay effect but I’m having difficulty preventing the background content from scrolling when the overlay is active. Here’s a CodePen…

https://codepen.io/moy/pen/xPmmZo

As you can see I’ve kept the jQuery to a minimal…

JavaScript

I’d also like to make the content box in the overlay a bit more flexible, currently if the viewports height isn’t that great, the box goes off the screen. I’d like to retain a bit of margin/padding vertically so it doesn’t leave the viewport and have either the overlay or box scrollable.

I’m trying to keep this an minimal as possible, hence why I’ve not using a plugin for this. Not too bothered about transitions/animations either.

Advertisement

Answer

Just make sure that your body‘s overflow is hidden

JavaScript

Demo

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement