JS实现的随机乱撞的彩色圆球特效代码.doc_第1页
JS实现的随机乱撞的彩色圆球特效代码.doc_第2页
JS实现的随机乱撞的彩色圆球特效代码.doc_第3页
JS实现的随机乱撞的彩色圆球特效代码.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

JS实现的随机乱撞的彩色圆球特效代码 HTML5学习第5天乱撞的球 body font-family: 微软雅黑; body,h1 margin:0; canvas display:block;margin-left: auto;margin-right: auto; border:1px solid #DDD; background: -webkit-linear-gradient(top, #222,#111); JS实现的随机乱撞的彩色圆球特效代码 stoprunaddBallvar nimo= aniamted:null, content:null, data: radiusRange:5,20, speedRange:-5,5, scrollHeight:null, scrollWdith:null , balls:, ele: canvas:null , fn: creatRandom:function(startInt,endInt)/生产随机数 var iResult; iResult=startInt+(Math.floor(Math.random()*(endInt-startInt+1); return iResult , init:function() nimo.data.scrollWdith=document.body.scrollWidth; nimo.data.scrollHeight=document.body.scrollHeight; nimo.ele.canvas=document.getElementById(canvas); nimo.content=nimo.ele.canvas.getContext(2d); nimo.ele.canvas.width=nimo.data.scrollWdith-50; nimo.ele.canvas.height=nimo.data.scrollHeight-100; , addBall:function() var aRandomColor=; aRandomColor.push(nimo.fn.creatRandom(0,255); aRandomColor.push(nimo.fn.creatRandom(0,255); aRandomColor.push(nimo.fn.creatRandom(0,255); var iRandomRadius=nimo.fn.creatRandom(nimo.data.radiusRange0,nimo.data.radiusRange1); var oTempBall= coordsX:nimo.fn.creatRandom(iRandomRadius,nimo.ele.canvas.width-iRandomRadius), coordsY:nimo.fn.creatRandom(iRandomRadius,nimo.ele.canvas.height-iRandomRadius), radius:iRandomRadius, bgColor:rgba(+aRandomColor0+,+aRandomColor1+,+aRandomColor2+,0.5) ; oTempBall.speedX=nimo.fn.creatRandom(nimo.data.speedRange0,nimo.data.speedRange1); if(oTempBall.speedX=0) oTempBall.speedX=1 if(oTempBall.speedY=0) oTempBall.speedY=1 oTempBall.speedY=nimo.fn.creatRandom(nimo.data.speedRange0,nimo.data.speedRange1); nimo.balls.push(oTempBall) , drawBall:function(bStatic) var i,iSize; nimo.content.clearRect(0,0,nimo.ele.canvas.width,nimo.ele.canvas.height) for(var i=0,iSize=nimo.balls.length;i=nimo.ele.canvas.width) oTarger.speedX=-(Math.abs(oTarger.speedX) if(oTarger.coordsX-oTarger.radius=0) oTarger.speedX=Math.abs(oTarger.speedX) if(oTarger.coordsY-oTarger.radius=nimo.ele.canvas.height) oTarger.speedY=-(Math.abs(oTarger.speedY) oTarger.coordsX=oTarger.coordsX+oTarger.speedX; oTarger.coordsY=oTarger.coordsY+oTarger.speedY; , run:function() nimo.fn.drawBall(); nimo.aniamted=setTimeout(function() nimo.fn.drawBall(); nimo.aniamted=setTimeout(arguments.callee,10) ,10) , stop:function() clearTimeout(nimo.aniamted) window.onload=function() nimo.fn.init(); var i; for(var i=0;i10;i+) nimo.fn.addBall(); nimo.fn.run(); document.getElementById(stop).onclick=function() nimo.fn.stop() document.getElementById(run).onclick=function() nimo.fn.stop() nimo.fn.run() document.getElementById(addBall).onclick=function() var i; for(var i=0;i10;i+) nimo.fn.addBall(); nimo.fn.drawBall(true); 郑州整形医院 44./ym02cnmxfwd/ 1./ 2./ym02ybzxwd/ 3./ym02chuzhouwd/ 4./ym02bbzxwd/ 5./ym02xbzxwd/ 6./ym02smzxdwd/ 7./ym02kczxwd/ 8./ym02pfmrdwd/ 9./ym02mblkdewd/ 10./ym02jfsxwd/ 11./ym02redjswd/ 12./ym02gsypwd/ 13./ym02kyjwd/ 14./ym02ydwd/ 15./ym02qydwd/

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论