JS动画与Velocity.js的结合
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
44
45
46
47
48
49
50 | <!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>Vue使用Velocity.js</title>
<script src="./vue.js"></script>
</head>
<body>
<div id="root">
<transition
name="fade"
@before-enter="handleBeforeEnter"
@enter="handleEnter"
@after-enter="handleAfterEnter"
>
<div v-if="show">
hello world
</div>
</transition>
<button @click="handleClick">切换</button>
</div>
<script>
new Vue({
el: "#root",
data: {
show: true
},
methods: {
handleClick: function() {
this.show = !this.show
},
handleBeforeEnter: function(el) {
el.style.color = 'red'
},
handleEnter: function(el, done) {
setTimeout(() => {
el.style.color = 'green';
}, 2000)
setTimeout(() => {
done()
}, 4000)
},
handleAfterEnter: function(el) {
el.style.color = 'black'
}
}
})
</script>
</body>
</html>
|
http://www.velocityjs.org/
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
44
45
46
47
48
49
50
51 | <!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>Vue使用Velocity.js</title>
<script src="./vue.js"></script>
<script src="./velocity.js"></script>
</head>
<body>
<div id="root">
<transition
name="fade"
@before-enter="handleBeforeEnter"
@enter="handleEnter"
@after-enter="handleAfterEnter"
>
<div v-if="show">
hello world
</div>
</transition>
<button @click="handleClick">切换</button>
</div>
<script>
new Vue({
el: "#root",
data: {
show: true
},
methods: {
handleClick: function() {
this.show = !this.show
},
handleBeforeEnter: function(el) {
el.style.opacity = 0;
},
handleEnter: function(el, done) {
Velocity(el, {
opacity: 1
}, {
duration: 1000,
complete: done
})
},
handleAfterEnter: function(el) {
console.log('动画结束')
}
}
})
</script>
</body>
</html>
|