动画效果

基本使用

方式1:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<template>
<div>
<button @click="isShow = !isShow">显示/隐藏</button>
<!-- apper默认开始就显示动画 -->
<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: aqua;
}

.hello-enter-active{
animation: move 1s;
}

.hello-leave-active{
animation: move 1s reverse;
}

@keyframes move{
from{
transform: translateX(-100%);
}
to{
transform: translateX(0px);
}
}
</style>

方式2:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<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">你好2呀!</h1>
</transition-group>
</div>
</template>

<script>
export default {
name:'Test2',
data() {
return {
isShow:true,
}
},
}
</script>

<style scoped>
h1{
background-color: aqua;

}
/* 进入的起点与离开的终点 */
.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>

第三方动画库

  • Animate.css

    1. 安装css库:npm install animate.css

    2. 直接引入样式:import ‘animate.css’

    3. 配置属性:

      1
      2
      3
      4
      5
      6
      <transition-group 
      appear
      name="animate__animated animate__bounce"
      enter-active-class="animate__swing"
      leave-active-class="animate__backOutLeft"
      >