Vue中的Js动画与Velocity.js的结合
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Vue中的Js动画与Velocity.js的结合</title> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script src="js/velocity.min.js"></script> </head> <body> <div id="root"> <!-- 动画执行前,动画执行中,动画执行后 入场动画:before-enter、enter、after-enter 出场动画:before-leave、leave、after-leave --> <transition name="fade" @before-enter="handleBeforeEnter" @enter="handleEnter" @after-enter="handleAfterEnter"> <div v-show="show">Harold</div> </transition> <button @click="handleBtnClick">change</button> </div> <script type="text/javascript"> var vm = new Vue({ el: '#root', data: { show: true }, methods: { handleBtnClick() { this.show = !this.show }, // handleBeforeEnter(el) { // console.log("beforeEnter") // el.style.color = "red" // }, // handleEnter(el, done) { // setTimeout(() => { // el.style.color = "green" // }, 2000) // setTimeout(() => { // done() // }, 4000) // }, // handleAfterEnter(el) { // el.style.color = '#000' // }, handleBeforeEnter(el) { el.style.opacity = 0 }, handleEnter(el, done) { Velocity(el, { opacity: 1 }, { duration: 1000, complete: done }) }, handleAfterEnter(el) { console.log("动画结束") }, } }) </script> </body> </html>
略懂,略懂....