<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title></title> <style> #box { width: 100px; height: 100px; background-color: skyblue; position: absolute; } #box1 { width: 100px; height: 100px; background-color: orange; position: absolute; } </style> </head> <body> <div id="box"></div> <div id="box1"></div> <input id="score"/> <script> var box1=document.getElementById('box'); var box2=document.getElementById('box1'); box2.οnmοusedοwn=function(event){ var disX=event.clientX-this.offsetLeft; var disY=event.clientY-this.offsetTop; box2.οnmοusemοve=function(event){ var zuo=event.clientX-disX; var top=event.clientY-disY; this.style.left=zuo+'px'; this.style.top=top+'px'; }} var l=Math.floor(Math.random()*496); var t=Math.floor(Math.random()*496); box1.top=box1.offsetTop; box1.style.left=l+'px'; var score=0; var timer = setInterval(function() { if(box1.offsetTop==box2.offsetTop||box1.offsetTop+1==box2.offsetTop||box1.offsetTop+2==box2.offsetTop||box1.offsetTop+3==box2.offsetTop||box1.offsetLeft==box2.offsetLeft||box1.offsetLeft-1==box2.offsetLeft||box1.offsetLeft-2==box2.offsetLeft||box1.offsetLeft-3==box2.offsetLeft){ box1.style.top=0+'px'; alert("抓到了") l=Math.floor(Math.random()*1000); t=Math.floor(Math.random()*1000); box1.style.left=l+'px'; box1.style.top=t+'px'; score+=1; } }, 100); var x=document.getElementById("score"); x.onchange = function(){ x=x.value; var timer1 = setInterval(function() { if(score==x){ alert("你赢了"); alert(x); alert("你发现了彩蛋,不是我——window(微软)中国(庄景旗)"); clearInterval(timer); clearInterval(timer1); } else{alert("输了")} },x*25000) } alert(x); </script> </body> </html>
大鱼吃小鱼
最新推荐文章于 2024-07-19 12:58:53 发布