加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.html 1.99 KB
一键复制 编辑 原始数据 按行查看 历史
张溢芳 提交于 2020-12-15 15:17 . no commit message
!<!DOCTYPE html>
<html>
<head>
<title>打地鼠</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="./css/index.css">
</head>
<body>
<div class="total">
<img src="./images/mouse.png">
<img src="./images/mouse.png">
<img src="./images/mouse.png">
<img src="./images/mouse.png">
<img src="./images/mouse.png">
<img src="./images/mouse.png">
<img src="./images/mouse.png">
<img src="./images/mouse.png">
<img src="./images/mouse.png">
<span class="timer">剩余时间:<span class="miao">10</span></span>
<span class="score">当前得分:<span class="fs">0</span></span>
<button class="start_game">开始游戏</button>
</div>
</body>
<script>
var time = 10;
var score = 0;
var btn_start_game = document.getElementsByClassName("start_game")[0];
var fs = document.getElementsByClassName("fs")[0];
var miao = document.getElementsByClassName("miao")[0];
var mouse_shu = document.getElementsByTagName("img");
var cd = mouse_shu.length;
console.log(Math.floor(Math.random() * cd ));
btn_start_game.onclick=function(){
this.style.visibility='hidden';
var timer = setInterval(function(){
var shu = Math.floor(Math.random() * cd);
mouse_shu[shu].style.visibility="visible";
var canclick = true;
mouse_shu[shu].onclick=function(){
this.src="./images/mouse2.png"
if(canclick){
fs.innerText = ++score;
}
canclick = false;
}
setTimeout(function(){
for (var i = 0; i < cd; i++) {
mouse_shu[i].src="./images/mouse.png"
mouse_shu[i].style.visibility="hidden";
}
},800);
},1600);
var timer2 = setInterval(function(){
// console.log(time--);
miao.innerText = time--;
if(time<0){
clearInterval(timer);
clearInterval(timer2);
btn_start_game.style.visibility='visible';
time=10;
miao.innerText = time;
fs.innerText = 0;
btn_start_game.innerText = "重新开始游戏"
}
},800)
}
</script>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化