Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide the scrollbar using JavaScript

How can the scrollbar be hidden? I want to do this because the scrollbar is not nice.

overflow:hidden is not useful, because my div element has many other elements.

So setting overflow does not solve my problem.

like image 235
zjm1126 Avatar asked Mar 21 '10 08:03

zjm1126


People also ask

How do you get rid of scrollbar?

To hide the vertical scrollbar and prevent vertical scrolling, use overflow-y: hidden like so: HTML. CSS.

How can I hide scrollbar in iframe but still scroll?

1. Set the overflow of the parent div as hidden. 2. Set the overflow of the child div to auto and the width 200% (or anything more than 100%, or more than the width of the parent - so that the scrollbar gets hidden).


1 Answers

You can hide the scrollbar with this...

document.body.style.overflow = 'hidden'; 

...and unhide it with this:

document.body.style.overflow = 'visible'; 

However, you have to question yourself whether this is really what you want. Scrollbars appear for people to be able to view things that are outside of their small screens.

like image 59
Whakkee Avatar answered Sep 29 '22 17:09

Whakkee