Javascript 禁用任何类型的浏览器窗口滚动?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10744542/
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 browser window scrolling of any kind?
提问by scriptgeeky
Is there a way to disable scrolling? Not just the scrollbar, but the entire functionality from the browser window?
有没有办法禁用滚动?不仅仅是滚动条,还有浏览器窗口的全部功能?
回答by Dejan.S
based on your answer to Keit you dont want to scroll be active when you have a lightbox open? if that is the case you can add a class to the body at the same time as you open the lightbox with the following css
根据您对 Keit 的回答,您不想在打开灯箱时滚动活动?如果是这种情况,您可以在使用以下 css 打开灯箱的同时向正文添加一个类
And the nice thing about this solution it keeps the scroll "space" so the site do not jump, its more like it disables it. hope this helps
这个解决方案的好处是它保持滚动“空间”,所以网站不会跳转,它更像是禁用它。希望这可以帮助
body.noscroll
{
position: fixed;
overflow-y: scroll;
width: 100%;
}
$('body').addClass('noscroll');
$('body').removeClass('noscroll');
回答by Keith
CSS
CSS
body
{
overflow: hidden;
}
javascript
javascript
document.body.style.overflow = "hidden";
jQuery
jQuery
$("body").css('overflow', 'hidden');
回答by Philippe Gonday
If your GWT application is alone in your web page, you can use:
如果您的 GWT 应用程序单独存在于您的网页中,您可以使用:
import com.google.gwt.user.client.Window;
// ...
Window.enableScrolling(false);
for example in your onModuleLoad
function.
例如在您的onModuleLoad
功能中。