在动画上强制垂直滚动条

发布于 2024-12-02 04:21:47 字数 262 浏览 3 评论 0原文

我有一个从 height: 0height: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

七分※倦醒 2024-12-09 04:21:47

您的动画库必须在外部元素上设置 overflow: hide,这就是滚动条消失的原因。

尝试将内容包装在另一个 div 中:

<!-- the outer element; pass this one to the animation lib -->
<div>
    <!-- the scroll bar will appear on this element -->
    <div style="overflow: scroll; height: 100%">
        <!-- content here -->
    </div>
</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:

<!-- the outer element; pass this one to the animation lib -->
<div>
    <!-- the scroll bar will appear on this element -->
    <div style="overflow: scroll; height: 100%">
        <!-- content here -->
    </div>
</div>

Try it here: http://jsfiddle.net/e3BkK/

天暗了我发光 2024-12-09 04:21:47

要始终显示垂直滚动条,您可以使用

#yourDivId {
  overflow-y: scroll;
}

如果您包含的内容的高度小于#yourDivId,则垂直滚动条将显示为禁用。

如果它的高度较大,则垂直滚动条将启用。

To always display a vertical scroll bar, you can use

#yourDivId {
  overflow-y: scroll;
}

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.

z祗昰~ 2024-12-09 04:21:47

通过 CSS 将 overflow:scroll 添加到 body 元素:http ://jsfiddle.net/GMcdf/1/

body {
    overflow: scroll;
}

Add overflow: scroll to the body element through CSS: http://jsfiddle.net/GMcdf/1/.

body {
    overflow: scroll;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文