爱易网
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 浏览次数:20105 次
以下是程序代码
<!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无刷新实现的分页代码箭头特效
免责声明:
本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
相关资料
更多>
看蜗牛如何放水养鱼,盘活生态系统
让一让,小米4来了,碰见米粉请务必绕道走!
聚美优品获基石投资1.5亿美金,IPO吃下定心丸
苹果iWatch或使用量产液态金属 将取代玻璃
全球网络遭史上最大规模攻击:攻击数据每秒300G
京东封杀财付通:终极目标是电商生态圈
刘强东:京东上市融资用于开拓三至六线城市
微软确认 Surface 计划更多尺寸和LTE 版本
中国移动4G资费调整方案6月1日起正式实施
推荐阅读
更多>
苹果多色彩!葫芦里究竟卖的什么药
看病也能用支付宝了 马云的又一盘大棋
苹果6月20日发布iPhone5S 触摸屏概念股生动
携程艺龙联手死磕同程 价钱烽烟蔓延至机票
三星手机在国内陷入困境:华为中兴小米紧追
雷军会做赔钱生意?迅雷跌破发行价 市值仅7亿美元
诺基亚因充电器问题暂停销售Lumia 2520平板电脑
逆转猜想:如果阿里成为雅虎大股东会怎样?
诺基亚依托规模效应 猛攻国际市场空白
广东移动高层受调查 中移动或现更大反腐风暴
快递企业征收“份子钱” 成全了谁 苦了谁?
Android应用审核乱象:诈骗软件冲上排行榜首
迪信通神秘免费服务揭谜底:充电宝免费带回家
陈天桥之鉴:产品创新被扼杀那些事
支付宝钱包支持医保移动缴费 广州成首个试点
谷歌董事长成花花公子:情史足以媲美涂鸦
中国电信内外受困 去电信化思绪待改
火狐手机发展前路:或被运营商绑架
网络文学竞争白热化 百度多酷文学网上线
从雷军的“互联网七字诀”告诉你一个非妖魔化的小米