首页 > 其他 > 详细

匀速运动

时间:2017-01-05 14:26:48      阅读:222      评论:0      收藏:0      [点我收藏+]
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>匀速运动</title>
<style>
#div1{width: 200px; height: 200px; background: blue; position: absolute; top:50px; left: 0px;}
</style>
<script type="text/javascript">
var timer = null;
function StartMove()
{    
    clearInterval(timer);
    var oDiv = document.getElementById(div1);
    timer = setInterval(function(){
        var speed = 10;
        if(oDiv.offsetLeft>=300)
        {
            clearInterval(timer);
        }
        else
        {
            oDiv.style.left = oDiv.offsetLeft + speed + px;
        }
    },30);
}
</script>
</head>
<body>
<input type = "button" id = "btn1" value = "开始运动" onclick = "StartMove()"/>
<div id = "div1"></div>
</body>
</html>

 

匀速运动

原文:http://www.cnblogs.com/pjw2017/p/6252126.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!