I'm trying to disable the html/body scrollbar of the parent while I'm using a lightbox. The main word here is disable. I do not want to hide it with overflow: hidden;
.
The reason for this is that overflow: hidden
makes the site jump and take up the area where the scroll was.
I want to know if its possible to disable a scrollbar while still showing it.
Look at your computer keyboard and locate the "Scroll Lock" key at the top, between the "Print Screen" and "Pause/Break" buttons. Click the "Scroll Lock" key and lock the scroll lock bar. When you lock the scroll bar, a small light appears on your keyboard.
To hide the horizontal scrollbar and prevent horizontal scrolling, use overflow-x: hidden: HTML. CSS.
If the page under the overlayer can be "fixed" at the top, when you open the overlay you can set
body { position: fixed; overflow-y:scroll }
you should still see the right scrollbar but the content is not scrollable. When you close the overlay just revert these properties with
body { position: static; overflow-y:auto }
I just proposed this way only because you wouldn't need to change any scroll event
Update
You could also do a slight improvement: if you get the document.documentElement.scrollTop
property via javascript just before the layer opening, you could dynamically assign that value as top
property of the body element: with this approach the page will stand in its place, no matter if you're on top or if you have already scrolled.
Css
.noscroll { position: fixed; overflow-y:scroll }
JS
$('body').css('top', -(document.documentElement.scrollTop) + 'px') .addClass('noscroll');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With