Hide the scrollbar but keep the ability to scroll

2019-02-22 07:04发布

问题:

I've searched for an answer to this question and came across hide scrollbar while still able to scroll with mouse/keyboard but the jQuery plugin doesn't quite do what I'd like to do. For one, the scrolling feels a bit sloppy and uncontrollable. The reason why I need this is simple: my page gets a little longer when you expand some items and the scrollbar appears out of the side and makes everything move to the left. I'd like to have a way to avoid this, by either being able to keep the scrollbar visible at all times or hiding it completely but still keep the native ability to scroll.

Here's an example of what I mean: http://screencast.com/t/Roi3HJtHyH when the long entry is clicked the content moves to the left, and this effect looks a little ugly.

回答1:

That is standard browser behavior.

Taking away scrollbar reduces user-friendliness.


You can set scrollbar to stay visible all the time with css.

CSS:

body {
    overflow-y: scroll;
}


回答2:

Just for completeness sake, to answer your question, here is the scrollable page without scrollbar.

Note that this is not preferred, and I would also force the scrollbar as Lobello already answered.



回答3:

If you really want to disable the scrolling (In a frameset, the worst possible place for scrolling) then use scrolling=no.



回答4:

This works for me:

    body{
        overflow:hidden;
    }