爱易网
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 浏览次数:20107 次
以下是程序代码
<!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无刷新实现的分页代码箭头特效
免责声明:
本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
相关资料
更多>
苹果股价突破100美元大关:投资者看好iPhone 6
支付宝曝平安破绽:转账信息被谷歌抓取
传搜狗估值12亿美元 与360谈判进入白热化
支付宝被曝严重破绽 隐私平安再受质疑
华为美国推出电商网站 发售Mate 2LTE版
美国电影协会在华起诉迅雷侵权 要求赔偿并道歉
快播灭了,还有西瓜:视频网站的灰色江湖还在
中移动一季度净利大降:手机补贴增长过快
世界杯让耐克阿迪大打出手 谁能劈开用户大脑?
推荐阅读
更多>
阿里国际化再落子:2.49亿美元投资新加坡邮政
微信将商场O2O战火烧到了阿里巴巴老家
论:三大运营商运用商店逆袭并非不能够
中电信国际漫游费下调85% 世界杯上网28元/天
首批四款“官方”打车软件发布:均为安卓版本
杨元庆去年总薪酬1.33亿元
微信企业号必须搬走四座大山,否则只能铩羽而归!
2013年至今中国互联网行业十大并购案汇总
刘强东:京东上市融资用于开拓三至六线城市
独立工具APP:为亿级用户的商业化而愁
传诺基亚Lumia928下月推出 将与iPhone5看齐
传诺基亚5月14日发布会推出Lumia 950
英特尔涉嫌垄断 欧盟或开出史上最高罚单
2019双12阿里云老用户怎么参加拼团活动 老用户拼团方法
余额宝收益率跌破5% 银行系宝宝收益率赶超
阿里巴巴上市后雅虎将面临更大的业绩压力
去看看外面的世界吧!别窝里斗了,中国在线旅游商们
Facebook以“人”为本的名义占领安卓
十亿美元的告别礼:三星为何要大举重组?
微软与摩托罗拉授权协议涵盖Android和Chrome设备