js缓动动画
   // 缓动动画
 // 封装缓动动画函数 传递两个参数 需要执行动画的对象和目标位置
 function animate (obj,target){
            //先把原先的定时器清除,只保留一个.
            clearInterval(obj.time);
             obj.time = setInterval( function(){
                 //步长 公式:(目标位置-现在的位置)/10
                //  Math.ceil 是往大的取整. Math.floor s是往小的取整;
                 var step =(target-obj.offsetLeft) / 20;
                 step = step > 0 ? Math.ceil(step): Math.floor(step);
                if(obj.offsetLeft == target){
                    clearInterval(obj.time);
                }
                obj.style.left = obj.offsetLeft + step +'px';
                obj.style.opacity=(obj.offsetLeft + step)/100
            },20);
        }
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号