日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

html5 制作会转的风扇,HTML5学习第5天[乱撞的球]可以听到风扇声的哟

發(fā)布時間:2025/3/15 HTML 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html5 制作会转的风扇,HTML5学习第5天[乱撞的球]可以听到风扇声的哟 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
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);

}

HTML5第5天[亂撞的球]

stop

run

addBall

var 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){//生產隨機數(shù)

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.radiusRange[0],nimo.data.radiusRange[1]);

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('+aRandomColor[0]+','+aRandomColor[1]+','+aRandomColor[2]+',0.5)'

};

oTempBall.speedX=nimo.fn.creatRandom(nimo.data.speedRange[0],nimo.data.speedRange[1]);

if(oTempBall.speedX===0){

oTempBall.speedX=1

}

if(oTempBall.speedY===0){

oTempBall.speedY=1

}

oTempBall.speedY=nimo.fn.creatRandom(nimo.data.speedRange[0],nimo.data.speedRange[1]);

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

var oTarger=nimo.balls[i];

nimo.content.beginPath();

nimo.content.arc(oTarger.coordsX,oTarger.coordsY,oTarger.radius,0,10);

nimo.content.fillStyle=oTarger.bgColor;

nimo.content.fill();

if(!bStatic){

if(oTarger.coordsX+oTarger.radius>=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<=0){

oTarger.speedY=Math.abs(oTarger.speedY)

}

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.οnlοad=function(){

nimo.fn.init();

var i;

for(var i=0;i<10;i++){

nimo.fn.addBall();

}

nimo.fn.run();

document.getElementById('stop').οnclick=function(){

nimo.fn.stop()

}

document.getElementById('run').οnclick=function(){

nimo.fn.stop()

nimo.fn.run()

}

document.getElementById('addBall').οnclick=function(){

var i;

for(var i=0;i<10;i++){

nimo.fn.addBall();

}

nimo.fn.drawBall(true);

}

}

by http://www.nimojs.com/

運行代碼

復制代碼

另存代碼

提示:您可以先修改部分代碼再運行

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結

以上是生活随笔為你收集整理的html5 制作会转的风扇,HTML5学习第5天[乱撞的球]可以听到风扇声的哟的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。