Javascript 如何禁用页面的滚动条?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3611379/
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
How can I disable the scroll bars of a page?
提问by faressoft
how to disable the scroll bars of the page.
如何禁用页面的滚动条。
and disable this button.
并禁用此按钮。


采纳答案by faressoft
$(window).scroll(function() {
scroll(0,0);
});
回答by palswim
The scrollbars are a CSS issue. You can add this to your page (or the inner part to a CSS file):
滚动条是 CSS 问题。您可以将其添加到您的页面(或 CSS 文件的内部部分):
<style type="text/css">
html, body {
overflow: hidden;
}
</style>
回答by Piskvor left the building
You can't disable that button (or any other method of scrolling the page); see this. However, you could scrollTo(0,0) anytime you detect scrolling. This might look ugly (page scrolls a bit, then jumps back up).
您不能禁用该按钮(或任何其他滚动页面的方法);看到这个。但是,您可以在检测到滚动时随时 scrollTo(0,0) 。这可能看起来很难看(页面滚动一点,然后跳回)。
For disabling the scrollbars, you can try setting html, body { overflow: hidden }; I think some browsers may not honor this.
要禁用滚动条,您可以尝试设置html, body { overflow: hidden };我认为某些浏览器可能不尊重这一点。
(Wouldn't it be better to just create a page that fits into the viewport, so that the scrollbars aren't shown?)
(创建一个适合视口的页面以便不显示滚动条不是更好吗?)
回答by Tristen
I am making a mobile website, but I don't want it to be a whole bunch of webpages, so I am making it one page with scrolling disabled. I did this with
我正在制作一个移动网站,但我不希望它成为一大堆网页,所以我将它制作成一个禁用滚动的页面。我做了这个
<style>
html, body {
overflow: hidden;
}
</style>
回答by Adam
document.body.scroll = "no";
document.body.style.overflow = 'hidden';
document.height = window.innerHeight;
should disable the scrollbars in most browsers.
应该在大多数浏览器中禁用滚动条。
请参阅:http: //www.eggheadcafe.com/community/aspnet/3/10088543/how-to-disable-document-body-from-scrolling.aspx
回答by Warren
This will remove your scroll bar. [I did it by accident]
这将删除您的滚动条。【我不小心弄的】
@media screen{
body>div#header{
position:fixed;
}
body>div#footer{
position:fixed;
} `
回答by Blue_Hat
This works:
* {overflow: hidden}One problem I have when figuring it out was that I have a CSS drop-down (well slide across) menu on the page and that doesn't show when I use this method. I am still trying to figure out how to get the drop-down to work with this enabled.
这是有效的:
* {overflow: hidden}我在弄清楚它时遇到的一个问题是我在页面上有一个 CSS 下拉菜单(很好地滑动),并且在我使用这种方法时没有显示。我仍在尝试弄清楚如何让下拉菜单启用此功能。

