【Vue中Js动画】
<html>
<head>
<meta charset="utf-8" />
<title>Vue中Js动画与velocity.js的结合</title>
<script src="./vue.js"></script>
<script src="./velocity.js"></script>
</head>
<body>
<div id="root">
<!--钩子函数@before-enter@before-leave@enter@leave@after-enter@after-leave-->
<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>
var vm = new Vue({
el: "#root",
data: {
show: true
},
methods: {
handleClick: function () {
this.show = !this.show
},
handleBeforeEnter: function (el) {
// console.log('beforeEnter')
el.style.color = "red"
},
handleEnter: function (el, done) {
setTimeout(() => {
el.style.color = "green"
}, 2000)
setTimeout(() => {
done()
}, 4000)
},
handleAfterEnter: function (el) {
el.style.color = "#000"
}
}
})
</script>
</body>
</html>
【velocity.js】
<html>
<head>
<meta charset="utf-8" />
<title>Vue中Js动画与velocity.js的结合</title>
<script src="./vue.js"></script>
<script src="./velocity.js"></script>
</head>
<body>
<div id="root">
<!--@before-enter@before-leave@enter@leave@after-enter@after-leave-->
<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>
var vm = new Vue({
el: "#root",
data: {
show: true
},
methods: {
handleClick: function () {
this.show = !this.show
},
/* handleBeforeEnter: function (el) {
// console.log('beforeEnter')
el.style.color = "red"
},
handleEnter: function (el, done) {
setTimeout(() => {
el.style.color = "green"
}, 2000)
setTimeout(() => {
done()
}, 4000)
},
handleAfterEnter: function (el) {
el.style.color = "#000"
}*/
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>