Vue的Js动画与Velocity.js的结合

@before-enter,在隐藏后,点击让它显示的时候,显示之前会触发。@enter不同,是在动画执行的过程中触发。done触发完成之后就是@after-enter。这些是通过js钩子来实现,也就是js来实现的:

成都创新互联主要从事成都网站建设、网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务黄浦,10余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18982081108




    
    
    
    
    


    
        //自定义class名字:
        
            hello
                 切换     
             var vm = new Vue({             el: "#root",             data: {                 show: true             },             methods: {                 handleClick: function() {                     this.show = !this.show                 },                 //el指的是动画包裹的标签                 handleBeforeEnter: function(el) {                     //console.log("handleBeforeEnter")                     //在标签从隐藏点击显示的时候,变成了红色                     el.style.color = "red"                 },                 //接收两个回调函数,el同上,done                 handleEnter: function(el, done) {                     //之前显示是红色,两秒后变成绿色                     setTimeout(()=>{                         el.style.color = "green"                     }, 2000)                     setTimeout(()=>{                         //但4秒才告诉vue结束(也就是2秒后变绿,又4-2秒后变黑)                         done() //这个done很重要,执行完之后要告诉vue,已经执行完                     }, 4000)                 },                 handleAfterEnter: function(el) {                     el.style.color = "black"                 }             }         });     

当然,除了入场动画,还有出场动画:




    
    
    
    
    


    
        //自定义class名字:
        
            hello
                 切换     
             var vm = new Vue({             el: "#root",             data: {                 show: true             },             methods: {                 handleClick: function() {                     this.show = !this.show                 },                 //el指的是动画包裹的标签                 handleBeforeLeave: function(el) {                     //console.log("handleBeforeLeave")                     //在标签从隐藏点击显示的时候,变成了红色                     el.style.color = "red"                 },                 //接收两个回调函数,el同上,done                 handleLeave: function(el, done) {                     //之前显示是红色,两秒后变成绿色                     setTimeout(()=>{                         el.style.color = "green"                     }, 2000)                     setTimeout(()=>{                         //但4秒才告诉vue结束(也就是2秒后变绿,又4-2秒后变黑)                         done() //这个done很重要,执行完之后要告诉vue,已经执行完                     }, 4000)                 },                 handleAfterLeave: function(el) {                     setTimeout(()=>{                         el.style.color = "black"                     }, 2000)                 }             }         });     

使用velocity。下载地址:http://velocityjs.org/




    
    
    
    
    
    


    
        //自定义class名字:
        
            hello
        
        切换
    
    
        var vm = new Vue({
            el: "#root",
            data: {
                show: true
            },
            methods: {
                handleClick: function() {
                    this.show = !this.show
                },
                //el指的是动画包裹的标签
                handleBeforeEnter: function(el) {
                    el.style.opacity = 0;
                },
                //接收两个回调函数,el同上,done
                handleEnter: function(el, done) {
                    //注意,要加上complete: done告诉vue结束
                    Velocity(el, {opacity:1}, {duration: 1000, complete: done})
                },
                handleAfterEnter: function(el) {
                    alert("动画结束")
                }
            }
        });
    


文章题目:Vue的Js动画与Velocity.js的结合
文章URL:http://azwzsj.com/article/iipgdi.html

其他资讯