爱易网
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 浏览次数:20108 次
以下是程序代码
<!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无刷新实现的分页代码箭头特效
免责声明:
本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
相关资料
更多>
2019双12阿里云老用户怎么参加拼团活动 老用户拼团方法
京东很忙:升服务推产品更新招股书 能赶在阿里前上市?
电信设备商淘金中国4G:华为中兴领衔
苏宁双线同价遇难题:第一个吃螃蟹不轻松
网友爆料称微软雇水军宣传主机Xbox One
喜大普奔:2016年国内乘客有望在飞机上使用手机
独立工具APP:为亿级用户的商业化而愁
摩托罗拉移动裁员关闭德州Moto X手机工厂
CSS控制字符长度和显示长度
推荐阅读
更多>
如家撤离同程内情:祸起反水OTA“联盟”?
谷歌安卓全球副总裁为何跳槽中国企业小米?
小米年度发布会遭围剿!多款新品难阻品牌危机
中国大陆人口13.7亿 光棍越来越多
Facebook思科联手推免费WiFi 欲覆盖全美
首家国有独资P2P平台上线 或预示政策日渐明朗
这一次,微软将带给我们什么惊喜?
Facebook财报前瞻:投资者仍信心不足
唯品会荣登“最贵中概股”的欢喜与哀愁
中兴通讯不打机海战术 将向中高端手机转型
三星起诉LG在冰箱广告中玷污其企业笼统
团购网站存活率仅18.6% 剩余缺乏千家
谁说黑莓没救?他们在悄悄地深耕企业级市场,在这个领域,苹果三星算什么,他们远远不是黑莓的对手
神州泰岳雪上加霜:副总违规买卖遭罚
完美入股盛大:一桩各怀心事的交易
中国邮政与阿里合作:邮政网点可做网购自提点
传谷歌开发者大会发布Android 4.3 并非5.0版本
扎克伯格华裔妻子首度亮相电视节目畅谈情史
苹果收购Beats交易或将延期尚需解决5大问题
评论:马云的成功建立在什么基础上很值得怀疑