简体   繁体   English

我们如何在使用jQuery的浏览器中禁用-不隐藏-滚动条?

[英]How do we disable - not hide - scrollbars in a browser using jQuery?

I would like to disable browser's scrolling when an event happens, but not remove the scrollbar ? 我想在事件发生时禁用浏览器的滚动,但不删除滚动条吗?

I would like something very similar to setting CSS's overflow:hidden to the whole document. 我想要与设置CSS的overflow:hidden到整个文档非常相似的东西。 My reason is that doing so changes the browser's width, hence I will have to re-align the body. 我的理由是这样做会改变浏览器的宽度,因此我将不得不重新对齐主体。

Why not just set the entire web page to align:center? 为什么不将整个网页设置为align:center? No manual re-aligning, and works with any screen resolution or browser :-) 无需手动重新对齐,并且可以与任何屏幕分辨率或浏览器一起使用:-)

The best practise fix to the problem I think you're describing is this simple CSS: 认为您要描述的问题的最佳实践解决方法是以下简单的CSS:

html {
    overflow-y: scroll
}

That forces the vertical scrollbar to always be visible, so that the browser's width will not change "when an event happens", and you won't "have to re-align the body". 这将强制垂直滚动条始终可见,这样浏览器的宽度就不会在“事件发生时”改变,并且您也不必“必须重新对齐正文”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM