首页 > 其他 > 详细

来回运动

时间:2020-03-11 16:42:42      阅读:79      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .box {
            width: 200px;
            height: 200px;
            background-color: gold;
            position: absolute;
        }
    </style>
    <script type="application/javascript">
        window.onload = function () {
        var box1 = document.getElementById(box);
        var speed = 5;
        var ileft = 0;

        var timer = setInterval(function () {
            ileft += speed;
            box1.style.left = ileft + px;
            if (ileft > 800){
                speed = -5;
            }
            if (ileft < 0){
                speed = 5;
            }
        },30);
        }
    </script>
</head>
<body>
    <div class="box" id="box"></div>
</body>
</html>

 

来回运动

原文:https://www.cnblogs.com/lurj/p/12463142.html

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