4

As per the title, is there a way to hide/remove the scrollbar from body (not a div, but the entire body) and keep the 'scrollable property' enabled? I've been trying different solutions in these days but nothing really worked.

Thank you in advance!

GiS91
  • 175
  • 1
  • 4
  • 12

6 Answers6

5

-webkit- solution from Fabian Schultz worked great, I added: -ms-overflow-style:none; to hide scrollbar on IE. Scroll enabled, scrollbar hidden.

This is the complete CSS:

::-webkit-scrollbar {
  display: none;
}

::-webkit-scrollbar-button {
  display: none;
}

body {
  -ms-overflow-style:none;
}
Community
  • 1
  • 1
wuzla
  • 71
  • 1
  • 5
0

In webkit browsers, you could use the scrollbar styling to "hide" it:

::-webkit-scrollbar {
  display: none;
}
::-webkit-scrollbar-button {
  display: none;
}

Example here.

Unfortunately this doesn't work in IE, Edge & Firefox.

Fabian Schultz
  • 18,138
  • 5
  • 49
  • 56
  • Your code runs smoothly in webkit browsers. Thank you! Two questions: 1) Do you know some hacks for Firefox and IE/Edge? 2) How can I achieve that dynamically with jQuery (for example: hide/remove the scrollbar and still being able to scroll after clicking a button)? – GiS91 Oct 10 '16 at 13:46
  • 1) Take a look at https://github.com/noraesae/perfect-scrollbar 2) I updated my example to have a toggle button for that CSS rule, but it doesn't work instantly. You need to wait a second after disabling the scrollbar for the change to take effect. – Fabian Schultz Oct 10 '16 at 14:00
  • 'Perfect scrollbar' does not seem to work. What I've done is: 1) Assigning an id="container" along with position:relative and height:100%; to body tag; 2) Initialising the plugin as indicated: var container = document.getElementById('container'); Ps.initialize(container); 3) Calling 'destroy' to destroy the scrollbar: Ps.destroy(container); Unfortunately, nothing happens. Parameters such as ' wheelSpeed' works well instead. – GiS91 Oct 11 '16 at 13:49
0

If you wrap the contents you don't want to scroll in <div class='hidden-scrollbar'>, and as an example, have your scrollable content in something like <div class='inner'>, something like:

<div class='hidden-scrollbar'>
    <div class='inner'>
        Lorem ipsum dolor sit amet...
    </div>
</div>

you can apply the following styles to remove the vertical scrollbar:

body {
    padding:50px;   
}

.hidden-scrollbar {
    background-color:black;
    border:2px solid #666;
    color:white;  
    overflow:hidden;
    text-align:justify;    
}

.hidden-scrollbar .inner {
    height:200px;
    overflow:auto;
    margin:15px -300px 15px 15px;
    padding-right:300px;
}

You might need to rework the contents of your page a bit, and it is a touch on the kludgy side, but as far as I know, it's the only way to get what you're looking for. Here's a fiddle that shows it in action.

autoboxer
  • 1,358
  • 1
  • 16
  • 37
0

Hiding the scrollbar and still keeping the functionality seems to be a hard thing to do on the body-element. But this might be a good enough solution for you:

CSS:

body{overflow:hidden;} 
body:hover {overflow:auto;}
Zorken17
  • 1,896
  • 1
  • 10
  • 16
-2

You can use the code below to hide vertical and horizontal scrolling. For detailed answer you can check this question.

<style type="text/css">
    body {
        overflow:hidden;
    }
</style>
Community
  • 1
  • 1
  • overflow:hidden removes the scrollbar as well as the possibility to scroll. What I want is to hide/remove the scrollbar but still being able to scroll. – GiS91 Oct 10 '16 at 12:53
  • in the link I sent people discuss that situation aswell. Read through the other answers. I didn't test them out but it seems like you have to arrange it for each browser. – Tümer Koloğlu Oct 10 '16 at 12:59
-2

Try this by a CSS solution

body{
      overflow : hidden
}

If same has to be done in jQuery

$("body").css("overflow", "hidden");

This should work like a charm.

  • Thank you, Kay. Yes, your solution removes the scrollbar but you're not able to scroll anymore. What I'm trying to get is removing the scrollbar but still being able to scroll. – GiS91 Oct 10 '16 at 12:59
  • This is not what OP are asking for. overflow: hidden; doesn't just hide the scrollbar, it also prevent the site from scrolling. – maverick Oct 10 '16 at 13:28