js运动3 匀速运动




    
    缓冲运动

    

    





js运动3 匀速运动_第1张图片
yunsu1.gif

 function move(){
                clearInterval(timer);
                timer = setInterval(function(){
                    var speed = (endPos - target.offsetLeft)/10;
                    speed = speed>0 ? 7 : -7;

                    if(Math.abs(endPos - target.offsetLeft) <= 7){
                        clearInterval(timer);
                        target.style.left = endPos+"px";
                    }else{
                        target.style.left = target.offsetLeft + speed + "px";
                    }

                    document.getElementsByTagName("span")[0].innerHTML = target.offsetLeft+ "," + speed;
                }, 30);
            }
js运动3 匀速运动_第2张图片
yunsu2.gif

你可能感兴趣的:(js运动3 匀速运动)