jQuery 如何禁用 body 元素的滚动?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2789126/
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 to disable scrolling of body element?
提问by Starx
How to disable scrolling of body? $('body').css('overflow','hidden');
only hides the scrollbars but it does not disable the scrolling. I want to disable the scrolling of the body.
如何禁用身体滚动?$('body').css('overflow','hidden');
仅隐藏滚动条,但不会禁用滚动。我想禁用身体的滚动。
But I want to keep the scrolling of other division intact.
但我想保持其他部门的滚动完好无损。
采纳答案by Makram Saleh
Try this CSS, no jQuery needed for this:
试试这个 CSS,不需要 jQuery:
<style type="text/css">
html { overflow: hidden; }
</style>
[UPDATE after comment]
[评论后更新]
Try specifying the height of the body
too:
尝试指定body
太高的高度:
<style type="text/css">
html, body { overflow: hidden; height: 100% }
body { margin:0; padding:0; }
</style>