jQuery添加/删除DOM元素:滚动条问题 [英] jQuery adding/removing DOM elements: Scrollbar issue

查看:435
本文介绍了jQuery添加/删除DOM元素:滚动条问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个jQuery函数,动态添加或删除DOM中的消息框。根据网站的内容和消息框的数量,浏览器滚动条出现。有时,只有一个消息框出现会导致该滚动条。当这个盒子被移除时,滚动条消失,整个站点横向跳跃几个像素。
有没有办法解决它?



我试过 overflow:hidden code>体。这当然是有效的,但也是毫无意义的,因为那样你就无法滚动网站的内容。 $ c> overflow-y:scroll 这将强制滚动条出现(当滚动条没有任何内容时,可以看到,但禁用了)。请参阅: http://html5boilerplate.com/docs/css/#html- (也为可能的陷阱)

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.

解决方案

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)

这篇关于jQuery添加/删除DOM元素:滚动条问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆