爱易网
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 浏览次数:20102 次
以下是程序代码
<!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无刷新实现的分页代码箭头特效
免责声明:
本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
相关资料
更多>
完美入股盛大:一桩各怀心事的交易
聚美优品获基石投资1.5亿美金,IPO吃下定心丸
银河证券王锦炎:金融业如何使用大数据
八位知名设计师评iOS7:新鲜但复杂
iOS7拖累iPad 5、iPad mini2发布 传十月份推出
微信企业号必须搬走四座大山,否则只能铩羽而归!
Docker Desktop 4.11 发布:支持虚拟桌面、Mac 权限更改和新扩展
郭美美事件推手被抓 “秦火火”拷问网络底线
探析APP移动营销发扬实效的微妙
推荐阅读
更多>
魅族黄章惹怒芙蓉姐姐 将跨界推女神手机
不提老罗,不说情怀,仅从十四个投诉问题入手谈锤子手机
微信今天大面积崩溃 腾讯:因光缆施工被挖断
国网公司将加快组建 业界人士称困难重重
云储存有多远:跨过数据安全问题即可到达
iSuppli:上网本将于2015年退出市场
承载京东C2C野心的拍拍网:梦想丰满,现实骨感
“论文查重”网店一月收入竟过百万
称产品遭诋毁 奇虎再诉百度
金山毒霸安全中心: XP退役后首个高危漏洞来了
苹果优势逐渐丧失 传即将推出廉价iPhone
新一代iPhone11月底国内上市 支持TD制式
中移动落马高管盘点:广东移动成反腐重地
挂号网高管团体离任 或因投资人失掉决计
电信设备商淘金中国4G:华为中兴领衔
中移动本月推手机钱包 iPhone遭边缘化
Skype周年:与微软联姻到底有没有未来?
摩托罗拉中国区将再裁员 助力公司变身
工商下月将整治手机市场
可靠消息称微型针孔偷拍设备拟全面禁止