gpt4 book ai didi

javascript - 同时在多个元素上使用 css 过渡

转载 作者:行者123 更新时间:2023-11-28 06:52:13 24 4
gpt4 key购买 nike

出于某种原因,当尝试同时为两个元素设置动画时(基于最大高度),过渡总是一次发生一个,第一个元素完成过渡后,另一个元素开始过渡。请看我在 js bin 上构建的这个例子来看看这个现象。

setTimeout(function () {
$(".b").css("max-height", "500px");
}, 500);

setTimeout(function () {
$(".b").css("max-height", "0");
$(".c").css("max-height", "500px");
}, 2000);

http://jsbin.com/riperifoku/edit?html,js,output

我将不胜感激任何有助于减轻这个谜团的帮助

最佳答案

嗨,你看起来像这样吗??据我了解,我认为这就是你想要的

setTimeout(function () {
$(".b").css("max-height", "500px");
$(".c").css("max-height", "500px");
}, 500);


setTimeout(function () {
$(".b").css("max-height", "0");
}, 2000);
    .box { background: red; height: 200px; width: 200px; margin: 15px; }
.a { height: 500px; width: 500px; background: blue; }

.b, .c { max-height: 0; overflow: hidden; transition: max-height 1s; transition-delay: 0; }
  <div class="a">

<div class="b">
<div class="box"></div>
</div>
<div class="c">
<div class="box"></div>
</div>

</div>

这是此代码的工作演示

<强> DEMO

关于javascript - 同时在多个元素上使用 css 过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32861412/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com