Skip to content

Commit bb6b5dc

Browse files
author
liandmin
committed
add blog
1 parent 6f37730 commit bb6b5dc

File tree

1 file changed

+105
-1
lines changed

1 file changed

+105
-1
lines changed

Articles/Vue中的过渡与动画.md

+105-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,109 @@
22

33
**[官网介绍](https://cn.vuejs.org/v2/guide/transitions.html)**
44

5-
### 基本用法
5+
**具体介绍**
6+
7+
Vue会在动画刚开始以及结束的时候,给动画元素添加相应的类名,具体如下图
8+
9+
开始动画
10+
![image](https://note.youdao.com/yws/api/personal/sync?method=download&fileId=992940EE4EB84D40A5950F832A5BCEF5&version=5806&cstk=XI9VrfDs)
11+
12+
结束动画
13+
![image](https://note.youdao.com/yws/api/personal/sync?method=download&fileId=3BFF7F21895A4DC1A3310DEEC731A522&version=5811&cstk=XI9VrfDs)
14+
15+
在开始动画时,添加默认类 `v-enter``v-enter-active`,在动画的下一帧开始的时候移除 `v-enter` 并添加 `v-enter-to`,并在动画结束的前一帧时移除所有`enter`
16+
17+
在结束动画开始前,添加默认类 `v-leave``v-leave-active`,并在动画结束的下一帧移除 `v-leave`,同时添加 `v-leave-to`,直到动画结束,移除所有的`v-leave`
18+
19+
再附上一张大图,解释的更加清楚
20+
![image](https://www.w3cplus.com/sites/default/files/blogs/2017/1709/vuejs-9.png)
21+
22+
可在transtion上设置`name="指定类名"`来覆盖默认类名
23+
24+
### 单元素/组件的过渡
25+
26+
[具体效果见此Demo](http://jsbin.com/pijavub/edit?html,css,output)
27+
28+
主要代码如下
29+
30+
```
31+
// CSS
32+
33+
.fade-enter, .fade-leave-to {
34+
opacity: 0;
35+
}
36+
.fade-enter-active, .fade-leave-active {
37+
transition: opacity 1s;
38+
}
39+
40+
// HTML
41+
42+
<div id="root">
43+
<transition name="fade">
44+
<p v-if="show">hello world</p>
45+
</transition>
46+
<button @click="handleClick">Toggle</button>
47+
</div>
48+
49+
// JS
50+
51+
new Vue({
52+
el: '#root',
53+
data: {
54+
show: true
55+
},
56+
methods: {
57+
handleClick () {
58+
this.show = !this.show
59+
}
60+
}
61+
})
62+
```
63+
64+
### 单元素/组件的动画
65+
66+
[具体效果见此Demo](http://jsbin.com/xuhutoc/edit?html,css,output)
67+
68+
过渡和动画可以设置自定义类名,主要代码如下
69+
70+
```
71+
@keyframes bounce-in {
72+
0% {
73+
transform: scale(0);
74+
}
75+
50% {
76+
transform: scale(1.5);
77+
}
78+
100% {
79+
transform: scale(1);
80+
}
81+
}
82+
83+
.enter {
84+
transform-origin: left center;
85+
animation: bounce-in 1s;
86+
}
87+
88+
.leave {
89+
transform-origin: left center;
90+
animation: bounce-in 1s reverse;
91+
}
92+
```
93+
94+
### 结合animate.css库使用
95+
96+
[具体效果见此Demo](http://jsbin.com/copowiw/edit?html,css,output)
97+
98+
主要就是利用了Vue可以自定义过渡和动画的类名来实现的,主要代码如下
99+
100+
```
101+
<transition name="fade"
102+
enter-active-class="animated swing"
103+
leave-active-class="animated shake"
104+
>
105+
```
106+
107+
### Vue中同时使用过渡和动画
108+
109+
6110

0 commit comments

Comments
 (0)