【问题标题】:Why do I get a delay when using CSS3 transitions?为什么在使用 CSS3 过渡时会出现延迟?
【发布时间】:2015-11-25 23:48:19
【问题描述】:

首先,只有我一个人吗?

http://jsfiddle.net/8kc0onqr/

我已经将动画制作得又好又长,以便能够区分它们,但在我的浏览器上 - Chromium 版本 45.0.2454.101 Ubuntu 14.04(64 位) - “关闭”动画延迟了 @987654322 的一部分@属性。

我尝试了各种缓动函数,但它们都表现出相同的行为,即一段时间内什么都没有发生,然后动画完成的速度比预期的要快。

jsfiddle的代码在下面重复,最初是从atzcss.com无耻地窃取

<div class="group">
    <input type="checkbox" 
        class="showhide" 
        id="showhide"
    />
    <label for="showhide">
        show/hide
    </label>


    <div class="subpane">
        <pre>
        lots
        of
        stuff
        so
        the
        pane
        is
        nice
        and
        tall
        for
        demonstration
        purposes
        </pre>
    </div>
</div>

.group {
    border: 1px solid #aaa;
}
.group label {
    font-size: 150%;
    font-weight: bold;
    width: initial;
    display: block;
    background-color: #F4EDFF;
    text-transform: capitalize;
}

.group input {
    display: none;
}

.group input ~ label:after {
    font-family: FontAwesome;
    /* fa-angle-double-down */
    content: "\f103";
}

.group input:checked ~ label:after {
    font-family: FontAwesome;
    /* fa-angle-double-up */
    content: "\f102";
}


.group input ~ .subpane {
    max-height: 0;
    overflow: hidden;
    transition: max-height 5s ease-out;
    transition-delay: 0;
}

.group input:checked ~ .subpane {
    max-height: 10000px;
    transition: max-height 3s ease-in;
    transition-delay: 0;
}

【问题讨论】:

    标签: css animation css-transitions


    【解决方案1】:

    这是一个有趣的案例。但是拆开它,你会发现max-height 是罪魁祸首。

    选中复选框后,窗格将显示max-height: 10000px。当您现在取消选中该复选框时,max-height逐渐动画化为0。也就是说,9999px,然后是9998px,...

    直到看到缩小的max-height 的视觉效果,它会持续一段时间。

    【讨论】:

    • 天哪,你是对的。澄清一下——在它最终到达那些没有被使用的像素之前,它会为几千个像素设置动画。但是为什么它在 atozcss.com 上可以正常工作呢? 编辑它没有!我需要找到解决方法。
    • 事实上,它不适合我 (Firefox)。在 this page 折叠“摘要”显示完全相同的行为。
    • @Altreus:将max-height 设置为更现实的预期值,而不是 10000 像素。那应该加快速度。否则你很可能不得不使用 JS。
    • @Harry 是的,你是对的。问题是,在原地,它可以是从 50px 到整个页面的任何东西!我希望避免 JS :(
    猜你喜欢
    • 2013-06-11
    • 2020-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-12
    • 2013-08-07
    • 1970-01-01
    • 2020-10-05
    相关资源
    最近更新 更多