<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript"> function setmove(){ var odiv=document.getElementById("div1"); clearInterval(timer) var timer=setInterval(function(){ var speed=1; if(odiv.offsetLeft>=900){ clearInterval(timer) } else{ odiv.style.left=odiv.offsetLeft+speed+"px" } },30) } </script> <style type="text/css"> *{ margin: 0; padding: 0; } #div1{ position: relative; background:red; width:200px; height:200px; } </style> </head> <body> <input type="button" name="" id="" value="开始" onclick="setmove()"/> <div id="div1"></div> </body></html>
添加回答
举报
0/150
提交
取消