码迷,mamicode.com
首页 > 编程语言 > 详细

javascript加速运动

时间:2014-06-16 13:05:38      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   java   http   ext   

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <style type="text/css">
        #div1
        {
            width: 100px;
            height: 100px;
            background-color: green;
            position: absolute;
            left:600px;
            top: 50px;
        }
        #div2
        {
            width:1px;
            height:300px;
            position:absolute;
            background-color:gray;
            left:300px;
            top:0px;
        }
    </style>
</head>
<script type="text/javascript">
    var timer = null;
    function Move() {
        var oDiv = document.getElementById("div1");
        timer = setInterval(function () {
            var speed = (300 - oDiv.offsetLeft) / 10;
            speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
            oDiv.style.left = oDiv.offsetLeft + Math.ceil(speed) + "px";
        }, 30);
    }
</script>
<body>
    <input type="button" id="btn" value="开始运动" onclick="Move()" />
    <div id="div1"></div>
    <div id="div2"></div>
</body>
</html>

  

javascript加速运动,布布扣,bubuko.com

javascript加速运动

标签:style   class   blog   java   http   ext   

原文地址:http://www.cnblogs.com/alphafly/p/3790129.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!