Using Vue 3.3.4, same behavior on Chrome and Firefox:
My code should play 1 animation and 1 transition at the same time for each 'enter' and 'leave' class.
Without type="animation" in the <Transition> tag with the same durations, everything works fine.
But when I specify type="animation" in the 'Transition' tag with a duration of 3 seconds for 'animation' and 1 second for 'transition', this is what happens:
Class 'enter': 'animation' 3s only.
Class 'leave': 'animation' & 'transition' 1s, while if I understood correctly, Vuejs should choose the longest duration.
So why 'animation' play only on the 'enter' class?
Why 1s chosen by Vuejs on the 'leave' class?
<template>
<button type="button" @click="flag = !flag">Toggle</button>
<transition name="zoom" type="animation">
<h2 v-if="flag">Hello</h2>
</transition>
</template>
<script>
export default {
name: "App",
data() {
return {
flag: false,
};
},
};
</script>
<style>
h2 {
width: 400px;
padding: 20px;
margin: 20px;
color: rgb(255, 255, 255);
}
.zoom-enter-active {
animation: zoom-in 3s linear forwards;
transition: all 1s linear;
}
.zoom-leave-active {
animation: zoom-out 3s linear forwards;
transition: all 1s linear;
}
.zoom-enter-from {
opacity: 0;
}
.zoom-leave-to {
opacity: 0;
}
@keyframes zoom-in {
from {
transform: scale(0, 0);
}
to {
transform: scale(1, 1);
}
}
@keyframes zoom-out {
from {
transform: scale(1, 1);
}
to {
transform: scale(0, 0);
}
}
</style>
Here is what happens on enter:
v-ifwithv-enter-fromclass setv-enter-fromis replaced byv-enter-activeandv-enter-to, transition and animation start playingv-enter-activeandv-enter-toare removed from the elementAnd on leave:
v-leave-fromis put on the element for a single framev-leave-fromis replaced byv-leave-activeandv-leave-to, transition and animation start playingv-enter-activeandv-enter-toare removed from the element and the element is removed from DOM throughv-ifSo while the
*-activeand*-toclasses are present on the element for the maximum duration of the transition and animation, the duration of the individual transition/animation is not changed.A transition of 1s gives you a hard limit on how long a fade-out animation is visible.