Html 防止在 HTML5 中滚动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15907436/
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
Prevent Scrolling in HTML5
提问by Phil
I would like to prevent all forms of page scrolling in my HTML5
application. I have tried searching on SO and Googlefor a general answer for Prevent all scrolling mechanisms, but everything is very specific - like how to disable scrolling with touches, or with arrow keys, or the scrollbars themselves.
我想防止我的HTML5
应用程序中所有形式的页面滚动。我曾尝试在 SO 和Google上搜索“防止所有滚动机制”的一般答案,但一切都非常具体 - 例如如何禁用触摸、箭头键或滚动条本身的滚动。
The reason I am looking for this is to be able to create a new div
below the visible screen, and animate it up (and down. This MoonBaseshows what I mean.), and I don't want the user to be able to scroll down to see it. Is this possible? Is there a meta
tag I can set? Or CSS
? - Or, am I taking the wrong approach to my animation? That is, would all my problems be fixed if I simply animated in from the side instead (and included the meta
tag width=device-width
)? Is that the closest way for me to get the desired behavior?
我正在寻找这个的原因是能够div
在可见屏幕下方创建一个新的,并向上(和向下。这个MoonBase显示我的意思。),我不希望用户能够滚动下来看看。这可能吗?有meta
我可以设置的标签吗?或者CSS
?- 或者,我是否对我的动画采取了错误的方法?也就是说,如果我只是从侧面动画(并包含meta
标签width=device-width
),我的所有问题都会得到解决吗?这是我获得所需行为的最接近方式吗?
回答by dersvenhesse
You don't need JavaScript, just use CSS. Set overflow: hidden;
:
您不需要 JavaScript,只需使用 CSS。设置overflow: hidden;
:
body {
overflow: hidden;
}