javascript 运动缓冲效果

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<style>
#box{
    width:100px;
    height:100px;
    background:orange;
    position: absolute;
    left:0;
}
</style>
<body>


    <div id="box"></div>

    
</body>
</html>
<script>

var oBox = document.getElementById('box');
var num = 0 , speed;


oBox.onclick = function(){
    setInterval(function(){
        speed = Math.ceil( 0.1*(1000-num) );
        num = num + speed;
        oBox.style.left = num+'px';
    },10);
}

</script>

 

posted @ 2014-12-24 23:32  Zion0707  阅读(127)  评论(0编辑  收藏  举报