Vue中的Js動畫與Velocity.js 的結合
阿新 • • 發佈:2018-11-26
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Vue中的Js動畫與Velocity.js的結合</title> <script src="./vue.js"></script> <script src="./velocity.min.js"></script> </head> <body> <div id="root"> <transition name="fade" @before-enter="handleBeforeEnter" @enter="handleEnter" @after-enter="handleAfterEnter"> <div v-show="show">hello world</div> </transition> <button @click="handleClick">toggle</button> </div> <script> var vm = 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> <!-- 入場動畫鉤子函式:@before-enter @enter @after-enter 出場動畫鉤子函式:@before-leave @leave @after-leave velocity.min.js是js動畫庫 -->
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Vue中的Js動畫與Velocity.js的結合</title> <script src="./vue.js"></script> <script src="./velocity.min.js"></script> </head> <body> <div id="root"> <transition name="fade" @before-enter="handleBeforeEnter" @enter="handleEnter" @after-enter="handleAfterEnter"> <div v-show="show">hello world</div> </transition> <button @click="handleClick">toggle</button> </div> <script> var vm = 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> <!-- 入場動畫鉤子函式:@before-enter @enter @after-enter 出場動畫鉤子函式:@before-leave @leave @after-leave velocity.min.js是js動畫庫 -->