1.使用动画完成过渡效果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/5361817b43e72e0dd11a517b41d6f551.gif)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
@keyframes myScale {
from{transform: scale(0)}
50%{transform: scale(2)}
to{transform: scale(1)}
}
@keyframes myMove{
0%{
transform: translateX(0);
}
50%{
transform: translateX(100px);
}
100%{
transform: translateX(200px) translateY(100px);
}
}
.scale-enter-active{
animation: myScale 2s;
}
.scale-leave-active{
animation: myScale 2s reverse;
}
.move-enter-active{
animation: myMove 2s ;
}
.move-enter-active{
animation: myMove 2s reverse;
}
</style>
<script src="vue.js"></script>
</head>
<body>
<div id="app">
<button type="button" @click="change=!change">变变变</button>
<transition name="scale" >
<h3 v-show="change">放大还是缩小,这是一个问题</h3>
</transition>
<transition name="move">
<h3 v-show="change">移动还是静止,这是一个问题</h3>
</transition>
</div>
</body>
<script>
let vm = new Vue({
el: "#app",
data: {
change:true,
},
methods: {},
});
</script>
</html>
2.使用第三方动画库来实现过渡效果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/c4e1cd1aa0879438fb7883faaa854451.gif)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="vue.js"></script>
<link rel="stylesheet" href="animate.css">
</head>
<body>
<div id="app">
<button type="button" @click="show=!show">toggle</button>
<transition enter-active-class="animated bounceInRight" leave-active-class="animated bounceOutLeft">
<h3 v-if="show">跳跃效果</h3>
</transition>
<transition enter-active-class="animated rotateIn" leave-active-class="animated rotateOut">
<h3 v-if="show">翻转效果</h3>
</transition>
</div>
</body>
<script>
let vm = new Vue({
el: "#app",
data: {
show:true
},
methods: {},
});
</script>
</html>