(编辑:jimmy 日期: 2024/11/19 浏览:2)
本文实例为大家分享了js实现连连看游戏的具体代码,供大家参考,具体内容如下
<!DOCTYPE html> <html> <head> <title>连连看</title> <meta charset="gbk"> <style type="text/css"> body { text-align: center; } .text {text-align: center; margin-top: 60px; color: #fff;} .agin {text-align: center; margin-top: 60px; color: #fff;} #game-box { margin: 60px auto; position: relative; } #game-box img { float: left; width: 59px; height: 59px; border: 1px solid #000000; } #game-box img.hover { border: 1px solid #ffffff; } #game-box img.active { border: 1px solid #7fff00; } #game-box div { background-color: #7fff00; position: absolute; } </style> <script type="text/javascript"> var byId = function (id) { return document.getElementById(id); } var boxWidth = 61; //格子宽度 var gameBox; var mapid = 'game-box';//地图 id //22张图片 var arr = '1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22'.split(','); var h = 8; //图片共8行 var w = 11; //图片共11列 var boxsLength = h*w; var boxArr = {}; //map对象 var startBox = ''; //开始的格子 var endBox = ''; //结束的格子 window.onload = init; //初始化 function init() { byId('agin').style.display = 'none';//隐藏再来一把按钮 boxsLength = h*w;//图片方框的个数 boxArr = {}; startBox = ''; endBox = ''; var str = ''; gameBox = byId(mapid); for (var i = 0; i < h; i++) { for (var j = 0; j < w; j++) { str += '<img class="" onclick="choose(this);" id="t' + i + '_l' + j + '" src="/UploadFiles/2021-04-02/blank.gif">以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。