JS动画效果,注意事件函数中所传递的传递的参数及某些事件函数返回的函数
1.进入动画钩子:before-enter,enter,after-enter;
2.离开动画钩子:before-leave,leave,after-leave;
3.在enter钩子中的函数调用done()告诉Vue,JS动画完成。
4.使用velocity.js动画库实现动画:Velocity(el,{样式属性},{duration:1000,complete:done})
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Vue中的JS与Velocity.js的结合</title> <script src="./vue.js"></script> </head> <body> <div id="root"> <transition name="fade" @befor-enter="handleBeforeEnter" @enter="handleEnter" @after-enter="handleAfterEnter"> <div v-show="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){ 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>