简单写一个比较拙的打字游戏,意在表明这个游戏实现的方式,仅此而已。
<button onClick="start()">开始</button>
<button onClick="stop()">停止</button>
<div id="dia" style="position: absolute;width:50px;height:50px;background:yellow;top:50px; left:0;"></div>
<div id="dia1" style="position: absolute;width:50px;height:50px;background:blue;top:50px; left: 200;"></div>
<div id="dia2" style="position: absolute;width:50px;height:50px;background:red;top:50px; left: 500;"></div>
var arr=new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","S","Y","Z");
var charInDiv='';
function start()
{
time=setInterval("move()",300);
}
function move()
{
dia.style.top=parseInt(dia.style.top)+20;
if(parseInt(dia.style.top)>500)
//如果div移动到大于500px时
{
dia.style.top=50;//返回到离top到50px
}