如何写一个通用的JavaScript效果库!(1/2)

2019-06-02 22:56:02王旭

    }, 
    run: function() { 
         if (this.isFinished())  return (this.options.onComplete || Prototype.emptyFunction)(this); 
         if (this.timer)   clearTimeout(this.timer); 
         this.duration -= this.fps; 
         this.steps--;                            
         var pos=1-this.steps/this.maxSteps    ;    //总进度的百分比 
         this.loop(this,pos);     
         (this.options.onUpdate || Prototype.emptyFunction)(this,pos);       
         this.timer = setTimeout(this.run.bind(this), this.fps); 
    }, 
    isFinished: function() {  
            return this.steps <= 0; 
    }, 
    setup:function(effect){       //初始化设置所有效果单元 
            for(var key in Effect.Init){ 
             if (typeof(Effect.Init[key])!="function") continue; 
             try{Effect.Init[key](this)}catch(x){} 
         } 
     }, 
    loop:function(effect,pos){           //执行所有效果单元 
         for(var key in Effect.Fn){ 
             if (typeof(Effect.Fn[key])!="function") continue; 
             try{Effect.Fn[key](effect,pos)}catch(x){} 
         } 
    } 
 } 

当动态效果改变的时候,比如淡出,我们让一个element慢慢的变淡变小,并消失。
在不用效果库的情况下 只用 element.style.display="none" 就做到了。