js实现图片慢慢移动到指定位置后停止,左右移动的看我代码错哪里了?急求

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
</head>
<body>
    <div id="box" style="width: 100px;height: 100px; background: blue;position:absolute;left:0;top:40px;"></div>
        <button type="button" id="start">开始</button>
        <script>
        window.onload = function () {
          var box = document.getElementById('box');
          var start = document.getElementById('start');
          var timer;
        }
         start.onclick = function () {
            timer = setInterval(animFn, 50);
          }
        
         function animFn () {
            box.style.left = parseInt(box.style.left) + 5 + 'px';
            
            box.style.left = '100px';
            window.clearInterval(timer);
          }
          
            

        </script>
</body>
</html>

木易老三
浏览 8423回答 0
0回答

慕莱坞2482426

12345609876

慕莱坞2482426

12345609876
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript