爱易网
IT新闻
IT新闻
爱易资讯
网站搭建
云虚拟主机教程
云服务器教程
Apache教程
IIS教程
Nginx教程
网站策划
站长文章
推广教程
淘宝客教程
网页设计
HTML教程
XHTML教程
CSS教程
HTML5教程
CSS3教程
JavaSript基础
JQuery教程
Node.js教程
前端技术
Ajax教程
Js特效
Xml教程
平面设计
页面UI设计
photoshop教程
程序开发
AI人工智能
Asp教程
Php教程
Asp.Net教程
Net Core教程
C#教程
Java教程
Jsp教程
开发技术
微信小程序教程
Uniapp开发教程
微信公众号开发
Andriod教程
IOS教程
DOS教程
Python教程
Docker教程
Windows Container教程
数据库
MSSQL教程
MySQL教程
Redis教程
Access教程
Oracle教程
数据库教程
操作系统
Linux教程
Windows教程
MAC教程
Cisco教程
交换机教程
防火墙教程
搜索
爱易网页
JS特效
一款基础模型的JS打飞机游戏特效代码
一款基础模型的JS打飞机游戏特效代码
日期:2014-05-18 浏览次数:20106 次
以下是程序代码
<!DOCTYPE html> <html lang="en"> <head> <title>一款基础模型的JS打飞机游戏特效代码</title> <style type="text/css"> #show{ margin:auto; width:300px; height:500px; background: black; position: relative; } #fly{ width:10px; height:10px; position:absolute; bottom:0; left:140px; background: #0044ff; } #sco{ z-index:1; color:white; } .arrow{ width:6px; height:6px; background: #ddd; margin-left: 2px; margin-top:-10px; } .huiji{ width:10px; height:10px; background: #eee; position:absolute; top:0; left:0; } </style> </head> <body> <div id="show" style="width:300px;height:500px"> <div id="fly"> <div class="arrow" style="margin-top:-10px;"> </div> </div> </div> </body> </html> <script> function $(id){//获得id return document.getElementById(id); } function keydown(e) {//判断键盘事件 var currKey=0,e=e||event; currKey=e.keyCode||e.which||e.charCode; return currKey; } function getClass(obj,attr){//getElementsByClass var aArray=[]; var i=0; var aAll = obj.getElementsByTagName('*'); for(i=0;i<aAll.length;i++){ if(aAll[i].className == attr){ aArray.push(aAll[i]); } } return aArray; } function fly(){ this.begin=0; this.arrowSpeed=5; this.huijiSpeed=7; this.showArea=$('show'); this.showWidth=this.showArea.style.width; this.showHeight=this.showArea.style.height; this.offsetleft='140px'; this.arrow=getClass(document,'arrow'); this.huiji=getClass(document,'huiji'); this.flying=$('fly'); this.scores=0; } fly.prototype={ constructor:fly, version:1.0, start:function(){ this.begin=1; }, end:function(){ this.begin=0; }, leftSet:function(width){ this.flying.style.left=width; return this.flying.style.left; }, process:function(){ var that=this; if(that.begin==0){ return false; }else if(that.begin==1){ that.leftSet(that.offsetleft); document.addEventListener('keydown',function(){//判断边界 if(parseInt(that.leftSet())>0&&parseInt(that.leftSet())<(parseInt(that.showWidth)-10)){ if(keydown()==37){ that.leftSet(parseInt(that.flying.style.left)-5+'px'); }else if(keydown()==39){ that.leftSet(parseInt(that.flying.style.left)+5+'px'); } }else if(parseInt(that.leftSet())==0){ if(keydown()==39){ that.leftSet(parseInt(that.flying.style.left)+5+'px'); } }else if(parseInt(that.leftSet())==(parseInt(that.showWidth)-10)){ if(keydown()==37){ that.leftSet(parseInt(that.flying.style.left)-5+'px'); } } }); setInterval(function(){//子弹 for(var i=0;i<that.arrow.length;i++){ if(Math.abs(parseInt(that.arrow[i].style.marginTop))<parseInt(that.showHeight)-10){ that.arrow[i].style.marginTop=parseInt(that.arrow[i].style.marginTop)-10+'px'; }else if(Math.abs(parseInt(that.arrow[i].style.marginTop))==parseInt(that.showHeight)-10){ that.arrow[i].style.marginTop='-20px'; } } },that.arrowSpeed); } }, huijiInit:function(){ var that=this, left=Math.random()*290, textnode=document.createElement('div'); that.showArea.appendChild(textnode).setAttribute('class','huiji'); textnode.style.left=0; textnode.style.top=0; textnode.style.left=left+'px'; setInterval(function(){ if(Math.abs(parseInt(textnode.style.top))<parseInt(that.showHeight)+10){ textnode.style.top=parseInt(textnode.style.top)+1+'px'; for(var i=0;i<that.arrow.length;i++){ if(Math.abs(par
上一篇:狡猾的按钮特效
下一篇:JS无刷新实现的分页代码箭头特效
免责声明:
本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
相关资料
更多>
创维冲击500亿梦想:转型硬件和内容供应商
小米盗版有理激怒乐视:提500部盗播证据猛追打
微软与摩托罗拉授权协议涵盖Android和Chrome设备
iSuppli:上网本将于2015年退出市场
云储存有多远:跨过数据安全问题即可到达
中兴引进黑莓三个核心团队
Kindle入华遭遇国内厂商“围剿 ” 电信也参战
传谷歌开发者大会发布Android 4.3 并非5.0版本
HTC曝出特大丑闻:高管诈骗+商业间谍
推荐阅读
更多>
富士康欲用机器人产iPhone 6
HTC手机为何一败再败?效果出在供应链
牟贵先挂帅 国美在线“价钱战”昔日开打
团购网站存活率仅18.6% 剩余缺乏千家
安全服务机构:公布2014年度最糟糕的25个密码
雅安地震 绝不宽恕应用人们爱心的骗子!
PC迎9年来出货量新低 平板电脑渐成主流
中移动业绩增长趋缓 目光转向海外市场
同为70前后人,马云为什么总是像外星人那么瘦
电信资费新政:三巨头压力大 短期降价仍有争议
阿里马云:我觉得互联网还有十年可以做
看,网络文学今日之繁盛;忆,纯真去哪了?
薛蛮子取保后首次发微博表示:辜负你们了
虚拟运营市场躁动:山西煤老板兴味浓重
CSS控制字符长度和显示长度
2018双11阿里云老用户怎么参加拼团活动 老用户拼团方法
虚拟运营商前路迷茫 业界建议发力车联网
高通反垄断案下月有望落定
网友爆料称微软雇水军宣传主机Xbox One
淘宝公布新规:升级售假卖家惩罚力度