兼容了IE,每得20分就加速一次!!!
效果如下:
图(1) 游戏初始
图(2) 游戏开始
代码如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <style> *{ margin: 0; padding: 0; } .box { margin: 50px auto 0 auto; width: 400px; height: auto; border: solid 1px #222; } #cont { width: 400px; height: 600px; position: relative; overflow: hidden; } #go { width: 100%; height: 600px; position: absolute; top: 0; font: 700 60px '微软雅黑'; text-align: center; z-index: 99; } #go span { cursor: pointer; background-color: #fff; border-bottom: solid 1px #222; } #main { width: 400px; height: 600px; position: relative; top: -150px; } .row { width: 400px; height: 150px; } .row div { width: 99px; height: 149px; border: solid 1px #222; float: left; border-top-width: 0; border-left-width: 0; cursor: pointer; } #count { border-top: solid 1px #222; width: 400px; height: 50px; font: 700 36px/50px '微软雅黑'; text-align: center; } </style> </head> <body> <div class="box"> <!-- 布局 --> <div id="cont"> <div id="go"> <span>Game start</span> </div> <div id="main"> </div> </div> <div id="count"></div> </div> </body> <script> //得当前样式 function getStyle(obj,arrt){ //兼容IE return obj.currentStyle "i"; } //移动div function move(obj){ //关闭上一个定时器 clearInterval(obj.timer); //默认速度与计分 var speed = 5,num = 0; //定时器管理与开启定时器 obj.timer = setInterval(function(){ //速度 var step = parseInt(getStyle(obj,'top')) + speed; //移动盒子 obj.style.top = step + 'px'; //判断并创建新的盒子 if(parseInt(getStyle(obj,'top')) >= 0){ cDiv('row'); obj.style.top = -150 + 'px'; } //删除边界外的盒子 if(obj.children.length == 6){ //删除前,如果有盒子没有点击则结束游戏 for(var i = 0;i<4;i++){ if(obj.children[obj.children.length - 1].children[i].className == 'i'){ //游戏结束 obj.style.top = '-150px'; count.innerHTML = '游戏结束,最高得分: ' + num; //关闭定时器 clearInterval(obj.timer); //显示开始游戏 go.children[0].innerHTML = 'Renew game'; go.style.display = "block"; } } obj.removeChild(obj.children[obj.children.length - 1]); } //点击与计分 obj.onclick = function(event){ //点击的不是白盒子 // 兼容IE event = event || window.event; if((event.target"#bbb"; //清除盒子标记 (event.target"block"; } //盒子加速 if(num%20 == 0){ speed++; } } },20) } //开始游戏 go.children[0].onclick = function(){ //开始前判断main里面是否有盒子,有则全部删除 if(main.children.length){ //暴力清楚main里面所有盒子 main.innerHTML = ''; } //清空计分 count.innerHTML = '游戏开始'; //隐藏开始盒子 this.parentNode.style.display = "none"; //调用定时器 move(main); } </script> </html>
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 纯音入心系列纯音乐《天籁古筝》1CD[MP3][331MB]
- 男女对唱典藏天碟《发烧对唱·那个季节里的歌DSD》10CD[WAV]
- 群星2010-歌林精选辑[歌林][WAV+CUE]
- TrioZimbalist-PianoTriosofWeinberg,Auerbach,Dvorak(2024)[24-44,1]wav
- 群星.1992-滚石第一流台湾歌·12王牌大车拼【滚石】【WAV+CUE】
- 林子祥.1984-创作歌集【华纳】【WAV+CUE】
- 周汤豪.2010-周汤豪【华纳】【FLAC分轨】
- Mozart-TheStringQuintets-AmadeusQuartet,CecilAronowitz(2017)[24-44,1][WAV+CUE]
- JamesWilliamsDennisIrwin-Focus(2024,Red)[24-48]FLAC
- 藤泽麻衣《空みあげて》[WAV]
- 纯音入心系列纯音乐《中国古筝经典名曲》1CD[MP3][1.3GB]
- 纯音入心系列纯音乐《古筝新奏:岁月静好与筝语,细水流年与筝同》1CD[MP3][846.9MB]
- 670《脆弱敏感小女生》[320K/MP3][27.53MB]
- 曾琳.2011-好好爱我【南方】【WAV+CUE】
- 范晓萱.1995-RAIN【福茂】【WAV+CUE】