<!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>
添加回答
举报
0/150
提交
取消