匀速运动

匀速运动
function startMove(target){
          clearInterval( timer );
          timer = setInterval( function(){
              var speed = target - oDiv.offsetLeft>0 ? 7  : -7;
              if( Math.abs( target - oDiv.offsetLeft ) <  7 ){
                   oDiv.style.left = target + "px";
                   clearInterval( timer );
              }else{
                   oDiv.style.left = oDiv.offsetLeft +  speed + "px";
              }
          },30 )
     }
 
匀速透明运动
var alpha = 30;// 操作透明度的变化
function startMove(target){
          clearInterval( timer );
          timer = setInterval( function(){
              var speed = target-alpha>0 ? 1 : -1;
              if( target == alpha ){
                   clearInterval( timer );
              }else{
                   alpha += speed;
                   oDiv.style.opacity =  alpha/100;
              }
          },30 )
     }
原文地址:https://www.cnblogs.com/tis100204/p/10297447.html