动画
1、创建动画
默认值是v-enter-active和v-leave-active
.v-enter-active {
animation: animate 1s;
}
.v-leave-active {
animation: animate 1s reverse;
}
@keyframes animate {
from {
transform: translateX(-100px);
}
to {
transform: translateX(0px);
}
}
2、创建标签执行动画
执行动画的标签用transition标签包裹,transition 标签设置了name="hello",对应的v-enter-active和v-leave-active要修改为hello-enter-active和hello-leave-active;
:appear="true"可以简写为appear。
<button @click="isShow = !isShow">显示/隐藏</button>
<transition name="hello" :appear="true">
<h1 v-show="isShow">你好啊</h1>
</transition>
过度
标签设置与动画一样,参考上面代码
1、设置过度时间
.hello-enter-active,.hello-leave-active {
transition: 0.5s linear;
}
2、开始起点和结束终点
.hello-enter,.hello-leave-to {
transform: translateX(-100%);
}
3、开始终点和结束起点
.hello-enter-to,.hello-leave {
transform: translateX(0px);
}
多个元素过度
使用transition-group
<transition-group name="hello" :appear="true">
<h1 v-show="isShow" key="1">你好啊</h1>
<h1 v-show="isShow" key="2">你好啊</h1>
</transition-group>
集成第三方动画
1、安装
yarn add animate.css
2、打开第三方动画网址:https://animate.style/,有诸多效果用法
<transition-group appear name="animate__animated animate__bounce" enter-active-class="animate__swing"
leave-active-class="animate__backOutUp">
<h1 v-show="isShow" key="3">你好啊</h1>
</transition-group>