jQuery adding/removing DOM elements: Scrollbar issue

一个人想着一个人 提交于 2019-12-12 02:55:02

问题


I wrote a jQuery function that dynamically adds or removes messages boxes from the DOM. Depending on the site's content and the number of message boxes, the browsers scrollbar appears. Sometimes, only the appearing of one message box causes that scrollbar. When this box is removed, the scrollbar disappears and the whole site jumps a few pixels sideways. Is there any way to fix it?

I've tried overflow: hidden on the body. This works of course, but is also pointless because then you can not scroll the site's content.


回答1:


You can use overflow-y: scroll which will force a scrollbar to appear (being visible, but disabled, when there is nothing to scroll). See: http://html5boilerplate.com/docs/css/#html- (also for possible pitfalls)



来源:https://stackoverflow.com/questions/9500791/jquery-adding-removing-dom-elements-scrollbar-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!