扫雷,学习资料:渡一教育实现扫雷视频,基本上所有都是原生js的,一个小bug用jquery解决,如果解决了bug再改,用了jq的地方会标注即写上js写法,大致实现效果如下
完整代码github地址:https://github.com/yuriaFan/mine-clearance
HTML部分,因为是学习+练习就只写了很普通的样式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="css/index.css">
<script src="js/jquery.js"></script>
<title>Document</title>
</head>
<body>
<div id="content">
<!-- 顶端按钮 -->
<div id="level">
<button class="active">初级</button>
<button>中级</button>
<button>高级</button>
<button class="big">重新开始</button>
</div>
<!-- 棋盘 -->
<div id="gameBox">
<!-- js动态添加的 -->
</div>
<!-- 底部文本 -->
<div id="bottomText">
<div class="text">剩余雷数:<span class="mineNum"></sapn></div>
</div>
</div>
<script src="js/index.js"></script>
</body>
</html>
三个部分,上部按钮,中部扫雷界面(‘棋盘’),下部剩余雷数text,中部‘棋盘’是用添加上去的
CSS部分,前面部分是对基础界面的样式修改,后面td.one-td.eight部分是给实现扫雷点击后出现的数字改颜色用的
注意 td的border-color,是用来实现‘棋盘’上宛如砖块一样的立体效果,设置上方和左侧为白色,其他地方为想要的颜色即可,
#content{
height: 900px;
margin: 0 auto;
width: 800px;
}
#level{
height: 25px;
width: 280px;
margin: 0 auto;
}
#level button{
height: 25px;
line-height: 25px;
width: 60px;
text-align: center;
background: rgb(73, 139, 141);;
color: white;
padding: 0px;
margin: 0px;
border: 0px;
border-radius: 5px;
outline: none;
cursor: pointer;
}
#level button.active{
background: #0bb9b6;
}
#level button.big{
width: 80px;
}
#gameBox{
padding-top: 20px;
}
#bottomText{
height: 20px;
width: 200px;
margin: 0 auto;
line-height: 20px;
}
/* .mineNum{
height: 20px;
width: 50px;
} */
table{
border-spacing: 1px;
background-color: #929196;
margin: 0 auto;
}
td{
height: