基于canvas實(shí)現(xiàn)的絢麗圓圈效果完整實(shí)例
本文實(shí)例講述了基于canvas實(shí)現(xiàn)的絢麗圓圈效果。分享給大家供大家參考,具體如下:
運(yùn)行效果截圖如下:

具體代碼如下:
<!DOCTYPE html>
<html>
<head>
<title>demo</title>
<style type="text/css">
body {
margin:0; background:black;
}
#canvas {
border:3px solid gray; box-shadow:0px 0px 2px 2px #D5D5D5; margin-left:100px; margin-top:50px;
}
#power {
position:fixed; bottom:50px; right:50px;
}
#power a {
color:green; text-decoration:none; display:inline-block; padding:20px; border:2px solid orange; box-shadow:0px 0px 2px 2px blue;
font-size:30px;
}
</style>
</head>
<body>
<canvas id="canvas" width="500px" height="500px"></canvas>
<script type="text/javascript">
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var colorList = "abcdefABCDEF0123456789".split("");
var colorListLength = colorList.length;
var arcList = [];
function createArc(attr) {
ctx.beginPath();
ctx.fillStyle = attr.color || "black";
ctx.arc(attr.x, attr.y, attr.r, 0, Math.PI*2);
ctx.closePath();
ctx.fill();
}
function color() {
var color = "#";
for(var i=0; i<6; i++) {
color += colorList[Math.round(Math.random()*colorListLength)];
}
return color;
}
function Arc() {
this.count = 0;
this.r = 5;
this.x = Math.round(Math.random()*500);
this.add = Math.round(Math.random()*5);
this.limit = Math.round(Math.random()*100)
this.mode = Math.round(Math.random());
var _self = this;
_self.run = function() {
if(_self.r >= _self.limit) {
_self.run = null;
return;
}
_self.x += _self.add*(_self.mode == 1 ? 1 : -1);
createArc({x: _self.x, y:Math.round(Math.random()*400), r: _self.r, color: color()});
_self.r += 5;
return _self;
};
return this;
}
var init_count = 150;
var init_time = 0;
var init = function() {
init_time++;
arcList.length = 0;
for(var i=0; i<init_count; i++) {
arcList.push(new Arc());
}
};
var reInit = function() {
var angle = Math.PI*2/init_count;
for(var i=0; i<init_count; i++) {
var _angle = i*angle;
createArc({x: 250 + 250*Math.cos(_angle), y: 250 + 250*Math.sin(_angle), r: 5, color:color()});
createArc({x: 250 + 200*Math.cos(_angle), y: 250 + 200*Math.sin(_angle), r: 5, color:color()});
createArc({x: 250 + 150*Math.cos(_angle), y: 250 + 150*Math.sin(_angle), r: 5, color:color()});
createArc({x: 250 + 100*Math.cos(_angle), y: 250 + 100*Math.sin(_angle), r: 5, color:color()});
}
};
init();
var globalInterval = setInterval(function() {
ctx.clearRect(0, 0, 500, 500);
var count = 0;
for(var i=0; i<init_count; i++) {
var arc = arcList[i];
arc.run ? arc.run() : count++;
}
if(count == init_count) {
if(init_time >= 2) {
reInit();
return;
}
init();
}
}, 100);
</script>
</body>
</html>
更多關(guān)于js特效相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery動(dòng)畫與特效用法總結(jié)》及《jQuery常見(jiàn)經(jīng)典特效匯總》
希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。
- JavaScript+html5 canvas繪制的圓弧蕩秋千效果完整實(shí)例
- javascript+HTML5的Canvas實(shí)現(xiàn)Lab單車動(dòng)畫效果
- javascript+HTML5的canvas實(shí)現(xiàn)七夕情人節(jié)3D玫瑰花效果代碼
- js+html5實(shí)現(xiàn)canvas繪制圓形圖案的方法
- js+html5實(shí)現(xiàn)canvas繪制簡(jiǎn)單矩形的方法
- js+html5實(shí)現(xiàn)canvas繪制鏤空字體文本的方法
- js+html5通過(guò)canvas指定開(kāi)始和結(jié)束點(diǎn)繪制線條的方法
- js+HTML5實(shí)現(xiàn)canvas多種顏色漸變效果的方法
- js+html5繪制圖片到canvas的方法
- html5 canvas js(數(shù)字時(shí)鐘)實(shí)例代碼
- 基于canvas實(shí)現(xiàn)的鐘擺效果完整實(shí)例
- JavaScript+html5 canvas繪制漸變區(qū)域完整實(shí)例
相關(guān)文章
bootstrap daterangepicker漢化以及擴(kuò)展功能
這篇文章主要為大家詳細(xì) 介紹了bootstrap daterangepicker漢化以及擴(kuò)展功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06
xmlplus組件設(shè)計(jì)系列之圖標(biāo)(ICON)(1)
這篇文章主要為大家詳細(xì)介紹了xmlplus組件設(shè)計(jì)系列之圖標(biāo)ICON的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05
JavaScript中你不知道的數(shù)學(xué)方法分享(非常實(shí)用)
JavaScript的Math對(duì)象包含了一些非常有用和強(qiáng)大的數(shù)學(xué)操作,可以在Web開(kāi)發(fā)中使用,本文為大家整理了一些非常實(shí)用的數(shù)學(xué)方法,希望對(duì)大家有所幫助2023-07-07
JS數(shù)組循環(huán)的方式以及效率分析對(duì)比
本文詳細(xì)講解了JS數(shù)組循環(huán)的方式以及效率分析對(duì)比,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-11-11
JavaScript聲明變量時(shí)為什么要加var關(guān)鍵字
var用來(lái)聲明變量,但是這個(gè)語(yǔ)法并不嚴(yán)格要求,很多時(shí)修改,我們可以直接使用一個(gè)變量而不用var聲明它,不過(guò)還是建議大家加var2014-09-09
小程序?qū)崿F(xiàn)人臉識(shí)別功能(百度ai)
這篇文章主要介紹了小程序?qū)崿F(xiàn)人臉識(shí)別功能(百度ai),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-12-12
JavaScript實(shí)現(xiàn)獲取img的原始尺寸的方法詳解
在微信小程序開(kāi)發(fā)時(shí),它的image標(biāo)簽有一個(gè)默認(rèn)高度,這樣你的圖片很可能出現(xiàn)被壓縮變形的情況,所以就需要獲取到圖片的原始尺寸對(duì)image的寬高設(shè)置,本文就來(lái)分享一下JavaScript實(shí)現(xiàn)獲取img的原始尺寸的方法吧2023-03-03
antd項(xiàng)目實(shí)現(xiàn)彩蛋效果的詳細(xì)代碼
這篇文章主要介紹了antd項(xiàng)目如何實(shí)現(xiàn)彩蛋效果,首先在components目錄下創(chuàng)建Transform目錄,包括index.css、index.js,index.js是主要的邏輯代碼,下面對(duì)代碼進(jìn)行分析,需要的朋友可以參考下2022-09-09

