在动画上强制垂直滚动条
我有一个从 height: 0
到 height: 80%
(主体的 80%)进行动画处理的 div,有时这个出现的 div 中的内容会比 div 更大,需要一个滚动条。
问题是滚动条在动画运行时不明显,并且仅在动画结束后需要时才出现。 (确实是一件好事)
但我很挑剔,因为我正在向我的网站添加最后的修饰,当滚动条随机出现时,它会将内容向左移动,看起来很有趣。
所以我希望滚动条无论如何都一直在那里。这可能吗?
I have a div that animated from height: 0
to height: 80%
(80% of the body) and sometimes the content in this appearing div will be bigger than the div, requiring a scroll bar.
Problem is the scroll bar isn't apparant when the animation is running, and it only appears when it needs to after the animation. (kinda a good thing really)
But I'm being picky because I'm adding the final touches to my site and when the scroll bar randomly appears, it shifts the content left and it just looks funny.
So I want the scroll bar to be there all the time regardless. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的动画库必须在外部元素上设置
overflow: hide
,这就是滚动条消失的原因。尝试将内容包装在另一个 div 中:
在此处尝试:http://jsfiddle.net/e3BkK/
Your animation library must be setting
overflow: hidden
on the outer element, which is why the scrollbar disappears.Try wrapping the content in one more div:
Try it here: http://jsfiddle.net/e3BkK/
要始终显示垂直滚动条,您可以使用
如果您包含的内容的高度小于
#yourDivId
,则垂直滚动条将显示为禁用。如果它的高度较大,则垂直滚动条将启用。
To always display a vertical scroll bar, you can use
If your contained content has a smaller height than
#yourDivId
, then the vertical scroll bar appears disabled.If it has a bigger height, then the vertical scroll bar becomes enabled.
通过 CSS 将
overflow:scroll
添加到body
元素:http ://jsfiddle.net/GMcdf/1/。Add
overflow: scroll
to thebody
element through CSS: http://jsfiddle.net/GMcdf/1/.