目录
091.动画效果
<template>
<div>
<button @click="isShow = !isShow">显示/隐藏</button>
<transition name="hello" appear>
<h1 v-show="isShow">你好啊</h1>
</transition>
</div>
</template>
<script>
export default {
name:'Test',
data() {
return {
isShow:true
}
},
}
</script>
<style scoped>
h1{
background-color: orange;
text-align: center;
}
/* 使用动画 来 */
.hello-enter-active{
animation: donghua 0.5s linear;
}
/* 使用动画 走 */
.hello-leave-active{
animation: donghua 0.5s linear reverse;
}
/* 定义动画 */
@keyframes donghua {
/* 从左边来 */
from{
transform: translateX(-100%);
}
to{
transform: translateX(0);
}
}
</style>
092.过度效果
<template>
<div>
<button @click="isShow = !isShow">显示/隐藏</button>
<transition name="hello" appear>
<h1 v-show="isShow">你好啊</h1>
</transition>
</div>
</template>
<script>
export default {
name:'Test',
data() {
return {
isShow:true
}
},
}
</script>
<style scoped>
h1{
background-color: orange;
text-align: center;
}
/* 进入的起点、离开的终点 */
.hello-enter,.hello-leave-to{
transform: translateX(-100%);
}
.hello-enter-active,.hello-leave-active{
transition: 0.5s linear;
}
/* 进入的终点、离开的起点 */
.hello-enter-to,.hello-leave{
transform: translateX(0);
}
</style>
093.多个元素过度
<template>
<div>
<button @click="isShow = !isShow">显示/隐藏</button>
<transition-group name="hello" appear>
<h1 v-show="!isShow" key="1">你好啊</h1>
<h1 v-show="isShow" key="2">西西歪</h1>
</transition-group>
</div>
</template>
<script>
export default {
name:'Test',
data() {
return {
isShow:true
}
},
}
</script>
<style scoped>
h1{
background-color: orange;
text-align: center;
}
/* 进入的起点、离开的终点 */
.hello-enter,.hello-leave-to{
transform: translateX(-100%);
}
.hello-enter-active,.hello-leave-active{
transition: 0.5s linear;
}
/* 进入的终点、离开的起点 */
.hello-enter-to,.hello-leave{
transform: translateX(0);
}
</style>
094.集成第三方动画
安装第三方库animate.css
npm i animate.css
<template>
<div>
<button @click="isShow = !isShow">显示/隐藏</button>
<transition-group
name="animate_animated animate_bounce"
enter-active-class="animate_swing"
leave-active-class="animate_backOutUp"
appear
>
<h1 v-show="!isShow" key="1">你好啊</h1>
<h1 v-show="isShow" key="2">西西歪</h1>
</transition-group>
</div>
</template>
<script>
import 'animate.css';
export default {
name:'Test',
data() {
return {
isShow:true
}
},
}
</script>
<style scoped>
h1{
background-color: orange;
text-align: center;
}
</style>
095.总结过度与动画
## Vue封装的过度与动画
1.作用:在插入、更新或移除DOM元素时,在合适的时候给元素添加样式类名
2.图示:
enter leave
opacity:0 -----> opacity:1 opacity:0 -----> opacity:1
| | | |
v-enter v-enter-to