本文实例为大家分享了JS实现贪吃蛇小游戏的具体代码,供大家参考,具体内容如下
document *{ margin:0px; padding:0px; } #board{ width:300px; height:500px; border:5px solid #000; margin:50px auto 0px; position: relative; background: #cccccc91; } li:first-child{ position: absolute; width: 10px; height:10px; left: 100px; top: 200px; background:cornflowerblue; z-index: 1; } li{ position: absolute; width: 10px; height:10px; background: pink; list-style: none; } li:nth-child(2){ left: 100px; top: 210px; } li:nth-child(3){ left: 100px; top: 220px; } p{ width: 10px; height: 10px; position: absolute; box-shadow: 0px 0px 2px 2px #000; border-radius: 50%; } #menu{ width:300px; height:30px; border:5px solid #000; border-top:none; margin:0px auto; position: relative; } #menu>button{ border: 0px; width: 75px; display: block; float: left; height: 30px; cursor: pointer; outline: none; } button:nth-child(1){ background: pink; } button:nth-child(2){ background: skyblue; } button:nth-child(3){ background: orange; } button:nth-child(4){ background: rgb(25, 230, 6); } button:hover{ font-size: 18px; color: white; font-weight: bold; } dl{ width: 75px; position: absolute; right:0; bottom:30px; cursor:pointer; display: none; height: 90px; } dl>dd{ display: block; cursor:pointer; text-align: center; line-height: 30px; } dl>dd:nth-child(1){ height: 30px; background: rgba(212, 118, 9, 0.527); } dl>dd:nth-child(2){ height: 30px; background: rgb(142, 6, 253); } dl>dd:nth-child(3){ height: 30px; background: rgb(205, 9, 231); }
- 菜鸟级
- 大师级
- 魔鬼级
小编还为大家准备了精彩的专题:javascript经典小游戏汇总
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。



