Vue之Velocityjs
# Vue使用Velocity.js实现动画
# 在 main.js引入Velocity
import Velocity from 'velocity-animate'
import '@/common/animate/velocity.ui.js' //这个js文件和上面的在同一个目录,此处我复制到本地修改
1
2
2
new Vue({
el: '#app',
Velocity,
components: {App},
template: '<App/>'
})
1
2
3
4
5
6
2
3
4
5
6
# 使用插槽实现动画复用
appear为进入时动画 , 要使用出现和消失的动画参考vuejs官网动画
<template>
<div id="VolecityAnimate">
<transition-group
appear
@before-appear="beforeAppear"
@appear="appear"
@appear-cancelled="appearCancelled">
<slot></slot>
</transition-group>
</div>
</template>
<script>
export default {
mirror: "#VolecityAnimate",
name: 'VolecityAnimate',
props: ['animateName'],//从父组件传来的动画名称
components: {},
data() {
return {}
},
methods: {
beforeAppear(mirror) {
mirror.style.opacity = 0
},
appear(mirror, done) {
Velocity(mirror, this.animateName, {
duration: 1500, delay: 1100
}, {
complete: done
});
},
},
}
</script>
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
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
# 引入之后使用
<volecity-animate :animateName="this.leftAnimate">
<article></article>
</volecity-animate>
1
2
3
2
3
Last Updated: 2023/01/30, 11:01:00