jQuery+css完成的连连看网页小游戏,有96个方块,每排放12块,一共放8排,现在有六个颜色的油漆桶,每个油漆桶的颜色不同,现在让这六种颜色随机涂抹这96个方块,有一点要求是每种涂色方块的总数是偶数。
为解决一些网页特效运行后不能显示效果(例如:jQuery则需要刷新)问题,特别新增网页版演示。
点击查看:网页特效
运行演示:
<!DOCTYPE html><html><head><title>基于jQuery开发的网页连连看小游戏_Veryhuo.COM</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><script type="text/javascript" src="http://www.wfuyu.com/uploads/common/js/jquery-1.4.2.min.js"></script><style type="text/css">*{margin:0px;padding:0px;}#test{width:388px; height: 260px; margin: 30px auto 0px; overflow: hidden; position: relative; background-color: #F1F1F1;}#test span{display: block; position: absolute; width: 30px; height: 30px; }</style></head><body><div id="test"></div><script type="text/javascript">function creSpan(n,mpId,mleft,mtop,bgcolor){var mSpan = document.createElement("span");var pId = mpId[0];pId.appendChild(mSpan);with(mSpan.style){left = mleft+"px";top = mtop+"px";background =bgcolor;}}</script><script type="text/javascript">$(function(){var arrColor = ["#FF00FF","#FFFF00","#00FFFF","#FF0000","#00FF00","#0000FF"];var myleft = 3;var mytop = 3;var arr = new Array();var test = $("#test");var arrtmp =[0,0,0,0,0,0];var tmpcolor =arrColor[0];for(var j=0;j<8;j++){arr[j] = new Array();if(j===7){for(var i=0;i<12;i++){if(i!==0){myleft+=32;}if(i===6){if(arrtmp[0]%2===0){arr[j][i] = new creSpan((j+1)*(i+1),test,myleft,mytop,arrColor[1]);arrtmp[1]++;}else{arr[j][i] = new creSpan((j+1)*(i+1),test,myleft,mytop,arrColor[0]);arrtmp[0]++;}}else if(i===7){if(arrtmp[1]%2===0){arr[j][i] = new creSpan((j+1)*(i+1),test,myleft,mytop,arrColor[2]);arrtmp[2]++;}else{arr[j][i] = new creSpan((j+1)*(i+1),test,myleft,mytop,arrColor[1]);arrtmp[1]++;}}else if(i===8){if(arrtmp[2]%2===0){arr[j][i] = new creSpan((j+1)*(i+1),test,myleft,mytop,arrColor[3]);arrtmp[3]++;}else{arr[j][i] = new creSpan((j+1)*(i+1),test,myleft,mytop,arrColor[2]);arrtmp[2]++;}}else if(i===9){if(arrtmp[3]%2==0){arr[j][i] = new creSpan((j+1)*(i+1),test,myleft,mytop,arrColor[4]);arrtmp[4]++;}else{arr[j][i] = new creSpan((j+1)*(i+1),test,myleft,mytop,arrColor[3]);arrtmp[3]++;}}else if(i===10){if(arrtmp[4]%2===0){arr[j][i] = new creSpan((j+1)*(i+1),test,myleft,mytop,arrColor[5]);arrtmp[5]++;}else{arr[j][i] = new creSpan((j+1)*(i+1),test,myleft,mytop,arrColor[4]);arrtmp[4]++;}}else if(i===11){if(arrtmp[5]%2===0){}else{arr[j][i] = new creSpan((j+1)*(i+1),test,myleft,mytop,arrColor[5]);arrtmp[5]++;}}else{tmpcolor=arrColor[parseInt(Math.random()*arrColor.length)];if(tmpcolor===arrColor[0]){arrtmp[0]++;}else if(tmpcolor===arrColor[1]){arrtmp[1]++;}else if(tmpcolor===arrColor[2]){arrtmp[2]++;}// Downloads By http://www.wfuyu.comelse if(tmpcolor===arrColor[3]){arrtmp[3]++;}else if(tmpcolor===arrColor[4]){arrtmp[4]++;}else if(tmpcolor===arrColor[5]){arrtmp[5]++;}arr[j][i] = new creSpan((j+1)*(i+1),test,myleft,mytop,tmpcolor);}}}else{for(var i=0;i<12;i++){if(i!==0){myleft+=32;}tmpcolor=arrColor[parseInt(Math.random()*arrColor.length)];if(tmpcolor===arrColor[0]){arrtmp[0]++;}else if(tmpcolor===arrColor[1]){arrtmp[1]++;}else if(tmpcolor===arrColor[2]){arrtmp[2]++;}else if(tmpcolor===arrColor[3]){arrtmp[3]++;}else if(tmpcolor===arrColor[4]){arrtmp[4]++;}else if(tmpcolor===arrColor[5]){arrtmp[5]++;}arr[j][i] = new creSpan((j+1)*(i+1),test,myleft,mytop,tmpcolor);}}mytop+=32;myleft=3;}var iclick = 0;var marr = new Array();var first = "";var second ="";$.each($("#test span"),function(k,v){$(this).click(function(){if(iclick===0){$(this).addClass("del");marr[0]=$(this).css("backgroundColor");first=k;}if(iclick===1){$(this).addClass("del");marr[1]=$(this).css("backgroundColor");second=k;}iclick++;if(iclick>=2){iclick=0;if(first!=second){if( marr[0]===marr[1]){$("#test").find(".del").detach();}else{$("#test span").removeClass("del");}}else{$("#test span").removeClass("del");}}});});});</script></body></html><div style="text-align:center;margin:30px 0 0 0;"><hr style="color:#999;height:1px;">如不能显示效果,请按Ctrl+F5刷新本页,更多网页代码:<a href='http://www.wfuyu.com/' target='_blank'>http://www.wfuyu.com/</a></div>提示:可修改后代码再运行!
上一篇 新手垃圾站一个月做到日3万IP实用攻略
下一篇 电脑忘记密码之找回密码的方法大汇总