javascript 禁用主窗口滚动 - Jquery
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22286675/
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
disable main window scrolling - Jquery
提问by Kadosh
I have a webpage with a lightbox in it, inside the lightbox there is a scrollbar. I want to disable the main window scrollbar and keep the lightbox scrollbar enabled.
我有一个带有灯箱的网页,灯箱内有一个滚动条。我想禁用主窗口滚动条并保持灯箱滚动条处于启用状态。
Not just to hide the scrollbar but to disable scrolling of the window at all (beside scrolling the lightbox).
不仅要隐藏滚动条,还要完全禁用窗口滚动(除了滚动灯箱)。
How can I do it?
我该怎么做?
采纳答案by Micha?
You probably need to call
你可能需要打电话
$("body").scroll(function(e){ e.preventDefault()});
when lightbox is opened.
当灯箱打开时。
You also may be interested with this question.
回答by Adrian Preuss
You dont need jQuery. Use Stylesheet:
你不需要jQuery。使用样式表:
html, body {
overflow: hidden;
}