【发布时间】:2021-08-19 22:49:19
【问题描述】:
我有一个自定义动画,常规的 Vue transition 并没有完全覆盖。我在其他地方用条件v-bind:class 实现了它,但这不适用于条件v-if 块或v-for 组。
我需要像v-enter-to一样在元素输入后一帧添加一个类('open'),但我需要它永远不会从元素中删除。
然后我需要在离开时将其移除以触发关闭动画。
我是否使用了 Vue 转换错误,而这在转换中是完全可能的,或者有没有办法围绕进入/离开功能添加/删除类?
.accordion {
overflow: hidden;
> div {
margin-bottom: -1000px;
transition: margin-bottom .3s cubic-bezier(.5,0,.9,.8),visibility 0s .3s,max-height 0s .3s;
max-height: 0;
overflow: hidden;
}
&::after {
content: "";
height: 0;
transition: height .3s cubic-bezier(.67,.9,.76,.37);
max-height: 35px;
}
&.open {
max-height: 8000px;
> div {
transition: margin-bottom .3s cubic-bezier(.24,.98,.26,.99);
margin-bottom: 0;
max-height: 100000000px;
position: relative;
}
&::after {
height: 35px;
max-height: 0;
transition: height .3s cubic-bezier(.76,.37,.67,.9),max-height 0s .3s;
}
}
}
<transition name="accordion" :duration="300">
<div class="accordion" v-if="equipmentSelections.length === 0">
<div>
<p>Begin by selecting equipment from the list</p>
</div>
</div>
</transition>
<transition-group name="accordion" :duration="300">
<div v-for="equipment in equipmentSelections" v-bind:key="equipment.unitNumber" class="accordion">
<div>
<h3 v-on:click="updateSelections(equipment)">{{equipment.unitNumber}}</h3>
</div>
</div>
</transition-group>
【问题讨论】: