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

歡迎訪問 生活随笔!

生活随笔

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

HTML

球动画设计HTML5,html5 canvas炫彩运动小球动画特效

發(fā)布時間:2023/12/18 HTML 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 球动画设计HTML5,html5 canvas炫彩运动小球动画特效 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

特效描述:html5 canvas 炫彩運動 小球動畫特效。html5用canvas加面向?qū)ο?制作的運動小球動畫特效

代碼結(jié)構(gòu)

1. HTML代碼

var canvas=document.getElementById("canvas");

var context=canvas.getContext("2d");

var maxWidth=canvas.width;

var maxHeight=canvas.height;

var colors = ["#33B5E5", "#0099CC", "#AA66CC", "#9933CC", "#99CC00", "#669900", "#FFBB33", "#FF8800", "#FF4444", "#CC0000"]

//隨機數(shù)

function random(min,max){

return Math.floor(Math.random()*(max-min)+min)

}

//構(gòu)造函數(shù)

function Ball(){

this.a=true;

this.b=true;

this.r=random(10,30);

this.ballColor={color: colors[Math.floor(Math.random() * colors.length)]}

this.vx=random(30,maxWidth-30);

this.vy=random(30,maxHeight-30);

this.ispeed=random(1,10);

this.ispeed2=random(1,10);

}

// 面向?qū)ο?/p>

Ball.prototype.moveBall=function(){

context.beginPath();

if (this.a) {

this.vx += this.ispeed;

if (this.vx>=maxWidth-this.r) {

this.a = false;

}

} else {

this.vx -= this.ispeed;

if (this.vx <= this.r) {

this.a = true;

}

}

if (this.b) {

this.vy+= this.ispeed2;

if (this.vy >= maxHeight-this.r) {

this.b = false;

}

} else {

this.vy -= this.ispeed2;

if (this.vy <= this.r) {

this.b = true;

}

}

context.fillStyle=this.ballColor.color;

context.arc(this.vx,this.vy,this.r,0,Math.PI*2,false);

context.fill();

}

var Aball=[];

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

Aball[i]=new Ball();

}

setInterval(function(){

context.clearRect(0,0,canvas.width,canvas.height)

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

Aball[i].moveBall();

}

},30)

總結(jié)

以上是生活随笔為你收集整理的球动画设计HTML5,html5 canvas炫彩运动小球动画特效的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。