Html 隐藏滚动条但保持以原生感觉滚动的能力
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6635513/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hide the scrollbar but keep the ability to scroll with native feel
提问by Gabriele Cirulli
I've searched for an answer to this question and came across hide scrollbar while still able to scroll with mouse/keyboardbut 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.
我已经搜索了这个问题的答案并遇到了 隐藏滚动条,同时仍然可以使用鼠标/键盘滚动,但是 jQuery 插件并不能完全满足我的需求。一方面,滚动感觉有点草率和无法控制。我需要它的原因很简单:当您展开某些项目并且滚动条出现在侧面并使所有内容都向左移动时,我的页面会变长一点。我想有一种方法来避免这种情况,通过能够始终保持滚动条可见或完全隐藏它但仍保持本机滚动能力。
Here's an example of what I mean: http://screencast.com/t/Roi3HJtHyHwhen the long entry is clicked the content moves to the left, and this effect looks a little ugly.
这是我的意思的一个例子:http://screencast.com/t/Roi3HJtHyH当点击长条目时,内容向左移动,这种效果看起来有点难看。
采纳答案by Joonas
That is standard browser behavior.
这是标准的浏览器行为。
Taking away scrollbar reduces user-friendliness.
取消滚动条会降低用户友好性。
You can set scrollbar to stay visible all the time with css.
您可以使用 css 将滚动条设置为始终可见。
CSS:
CSS:
body {
overflow-y: scroll;
}
回答by NGLN
Just for completeness sake, to answer your question, here is the scrollable page without scrollbar.
为了完整起见,为了回答您的问题,这里是没有 scrollbar 的可滚动页面。
Note that this is not preferred, and I would also force the scrollbar as Lobello already answered.
请注意,这不是首选,我也会强制滚动条,因为 Lobello 已经回答了。
回答by Eman yalpsid
If you really want to disable the scrolling (In a frameset, the worst possible place for scrolling) then use scrolling=no.
如果你真的想禁用滚动(在框架集中,最糟糕的滚动位置)然后使用 scrolling=no。
回答by taptone
This works for me:
这对我有用:
body{
overflow:hidden;
}