过度
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box{
width: 150px;
height: 150px;
background-color: purple;
margin: 50px auto;
}
.fade-enter{
transform: translateX(-500px) rotate(-720deg) scale(0);
opacity: 0;
}
.fade-enter-active,.fade-leave-active{
transition: all 1s;
}
.fade-leave-to{
transform:translateY(500px) rotate(720deg) scale(0);
}
</style>
</head>
<body>
<div id="app">
<button @click="show"> {{ isShow?'消失':'显示' }} </button>
<transition name="fade">
<div class="box" v-if="isShow"></div>
</transition>
</div>
<script src="./vue.js"></script>
<script>
const vm = new Vue({
el: '#app',
data: {
isShow: false
},
methods: {
show(){
this.isShow = !this.isShow;
}
}
})
</script>
</body>
</html>
transition组件通过条件渲染 包裹多个元素
添加mode属性控制 出场动画 和入场动画的 执行 顺序
## 动画
```html
定义动画
//关键针
<style>
@keyframes 动画名{
0%{
}
25%{
}
50%{
}
75%{
}
100%{
}
}
</style>
使用动画
animation-name
animation-duration
animation-delay
animation-timing-function linear ease ease-in
animation-iteration-count n infinite
animation-direction normal reverse alternate alternate-reverse
animation-play-state pause running
animation-fill-mode forward backward both
animation: name duration delay 后面顺序随便
animation.css插件
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box{
width: 200px;
height: 200px;
background-color: red;
margin: 50px auto;
}
</style>
<link rel="stylesheet" href="./animate.css">
</head>
<body>
<div class="box animate__animated animate__tada"></div>
</body>
## 列表动画
<transition-group></ransition-group>