Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable scroll without hiding it?

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.

like image 905
Dejan.S Avatar asked Jan 02 '12 14:01

Dejan.S


People also ask

How do I freeze the scroll bar?

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.

How do I disable scrolling on my website?

To hide the horizontal scrollbar and prevent horizontal scrolling, use overflow-x: hidden: HTML. CSS.


1 Answers

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'); 
like image 158
Fabrizio Calderan Avatar answered Sep 25 '22 17:09

Fabrizio Calderan