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.
If the page under the overlayer can be "fixed" at the top, when you open the overlay you can set
you should still see the right scrollbar but the content is not scrollable. When you close the overlay just revert these properties with
I just proposed this way only because you wouldn’t need to change any scroll event
What if I already scrolled the page?
if you get the
document.documentElement.scrollTopproperty via javascript just before the layer opening, you could dynamically assign that value astopproperty of thebodyelement: with this approach the page will keep its current scroll position, no matter if you’re on top or if you have already scrolled.Css
JS