一款由html5 canvas实现五彩小圆圈背景特效
之前介绍了好几款html5 canvas实现的特效。今天要为大家介绍一款由html5 canvas实现五彩小圆圈背景特效。五彩的小圆圈渐显渐失的特效。效果图如下:

html代码:
<canvas>
</canvas>
<div id="Circle">
<span>Harris Carney<span>
</div>
css代码:
body
{
margin:;
overflow: hidden;
background: #E9E9E9;
} #Circle
{
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
width: 150px;
height: 150px;
border-radius: 150px;
background: url('1.jpg');
} #Circle:before
{
content: '';
position: absolute;
top: -8px;
left: -8px;
width: 162px;
height: 162px;
border-radius: 162px;
border: 2px solid #BCBCBC;
} #Circle:after
{
content: '';
position: absolute;
top: -13px;
left: -13px;
width: 172px;
height: 172px;
border-radius: 172px;
border: 2px solid #FF9900;
} #Circle span
{
position: absolute;
bottom: -60px;
display: block;
width: 150px;
text-align: center;
font-family: 'Oswald';
color: #333;
font-size: 25px;
}
js代码:
var canvas = $('canvas')[0];
var context = canvas.getContext('2d');
function Dot() {
this.alive = true;
this.x = Math.round(Math.random() * canvas.width);
this.y = Math.round(Math.random() * canvas.height);
this.diameter = Math.random() * 7;
this.colorIndex = Math.round(Math.random() * 3);
this.colorArray = ['rgba(255,153,0,', 'rgba(66,66,66,', 'rgba(188,188,188,', 'rgba(50,153,187,'];
this.alpha = 0.1;
this.color = this.colorArray[this.colorIndex] + this.alpha + ')';
this.velocity = { x: Math.round(Math.random() < 0.5 ? -1 : 1) * Math.random() * 0.7, y: Math.round(Math.random() < 0.5 ? -1 : 1) * Math.random() * 0.7 };
}
Dot.prototype = {
Draw: function () {
context.fillStyle = this.color;
context.beginPath();
context.arc(this.x, this.y, this.diameter, 0, Math.PI * 2, false);
context.fill();
},
Update: function () {
if (this.alpha < 0.8) {
console.log(this.color);
this.alpha += 0.01;
this.color = this.colorArray[this.colorIndex] + this.alpha + ')';
console.log('===' + this.color);
}
this.x += this.velocity.x;
this.y += this.velocity.y;
if (this.x > canvas.width + 5 || this.x < 0 - 5 || this.y > canvas.height + 5 || this.y < 0 - 5) {
this.alive = false;
}
}
};
var EntityArray = [];
function Initialize() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
for (var x = 0; x < 100; x++) {
EntityArray.push(new Dot());
}
Update();
}
function Update() {
if (EntityArray.length < 100) {
for (var x = EntityArray.length; x < 100; x++) {
EntityArray.push(new Dot());
}
}
EntityArray.forEach(function (dot) {
dot.Update();
});
EntityArray = EntityArray.filter(function (dot) {
return dot.alive;
});
Draw();
requestAnimationFrame(Update);
}
function Draw() {
context.clearRect(0, 0, canvas.width, canvas.height);
EntityArray.forEach(function (dot) {
dot.Draw();
});
}
$(window).resize(function () {
EntityArray = [];
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
});
Initialize(); //@ sourceURL=pen.js
注:本文爱编程原创文章,转载请注明原文地址:http://www.w2bc.com/Article/6835
一款由html5 canvas实现五彩小圆圈背景特效的更多相关文章
- 一款基于HTML5 Canvas的画板涂鸦动画
今天给各网友分享一款基于HTML5 Canvas的画板涂鸦动画.记得之前我们分享过一款HTML5 Canvas画板工具,可以切换不同的笔刷,功能十分强大.本文今天要再来分享一款基于HTML5 Canv ...
- 基于HTML5 Canvas实现的图片马赛克模糊特效
效果请点击下面网址: http://hovertree.com/texiao/html5/1.htm 一.开门见山受美国肖像画家Chuck Close的启发,此脚本通过使用HTML5 canvas元素 ...
- HTML5 Canvas 奔跑的小狗
效果如上图,共六个图像切换,形成小狗动态奔跑效果.完整代码和图片请从 https://files.cnblogs.com/files/xiandedanteng/runningDog.rar 下载. ...
- 4款基于html5 canvas充满想象力的重力特效
今天给大家分享4个物理和重力实验,用来展示 html canvas 的强大.几年前,所有这些实验都必须使用 Java 或 Flash 才能做.在下面这些惊人的例子中,就个人而言,我比较喜欢仿真布料的那 ...
- smoke.js是一款基于HTML5 Canvas的逼真烟雾特效js插件。通过该js插件,可以非常轻松的在页面中制作出各种烟雾效果。
Smoke.js 是一个浏览器默认警告系统的JavaScript替代品,如果你想要跨浏览器与平台的标准化JavaScript警告窗口,Smoke.js就是你想要的. Smoke.js是一个轻量级且灵活 ...
- 程序猿必备的10款超炫酷HTML5 Canvas插件
1.超炫酷HTML5 Canvas 3D旋转地球动画 这是一款基于HTML5 Canvas的3D地球模拟动画,动画以太空作为背景,地球在太空中旋转,同时我们也可以拖拽鼠标来从不同的角度观察地球.另外我 ...
- 9款基于HTML5/SVG/Canvas的折线图表应用
1.华丽的HTML5图表 可展示实时数据 HTML5在图表应用中也十分广泛,比起以前的网页图表,HTML5图表制作更便捷,功能更强大.这款HTML5图表插件外观十分华丽和专业,在数据展示方面也很有优势 ...
- 16个富有创意的HTML5 Canvas动画特效集合
HTML5技术正在不断的发展和更新,越来越多的开发者也正在加入HTML5阵营,甚至在移动开发上HTML5的地位也是越来越重要了.HTML5中的大部分动画都是通过Canvas实现,因为Canvas就像一 ...
- 16个非常有趣的HTML5 Canvas动画特效集合
HTML5技术正在不断的发展和更新,越来越多的开发者也正在加入HTML5阵营,甚至在移动开发上HTML5的地位也是越来越重要了.HTML5中的大部分动画都是通过Canvas实现,因为Canvas就像一 ...
随机推荐
- 16、java包装类
一.包装类的由来: JAVA是面向对象的编程语言,但它也包含了8种基本数据类型,这8个基本数据类型不支持面向对象的编程机制,基本数据类型的数据也不具备“对象”的特性:没有属性,方法可以被调用.JAVA ...
- python3.x 和 python2.x关于 urllib的用法
在python2.x版本中可以直接使用import urllib来进行操作,但是python3.x版本中使用的是import urllib.request来进行操作,下面是简单的例子: python2 ...
- WINDOWS操作系统中可以允许最大的线程数
默认情况下,一个线程的栈要预留1M的内存空间 而一个进程中可用的内存空间只有2G,所以理论上一个进程中最多可以开2048个线程 但是内存当然不可能完全拿来作线程的栈,所以实际数目要比这个值要小. ...
- docker login harbor出现的报错Error response from daemon: Get https://172.16.1.99/v1/users/: dial tcp 172.16.1.99:443: getsockopt: connection refused解决方法
出现的问题 [root@master01 ~]# docker login 172.16.1.99 Username: admin Password: Error response from daem ...
- 60款与DevOps相关的开源工具
原文地址:https://elasticbox.com/blog/de ... ools/ 你喜欢免费的东西吗?获得开发者社区支持的自动化,开源的工具是大家梦寐以求的.这里列举了 60+ 款最棒的开源 ...
- android LinearLayout设置selector不起作用解决
设置方法 : android:background="@drawable/fen_selector" 如果只有这个的话,是不起作用的.还必须加上: android:clickabl ...
- AR_标准应收过账至总账基本操作(流程)
2014-06-04 Created By BaoXinjian
- android 屏幕适配问题
转自http://blog.sina.com.cn/s/blog_74c22b210100tn3o.html 如何将一个应用程序适配在不同的手机上,虽然这不算是一个技术问题,但是对于刚刚做屏幕的开发人 ...
- Python hypot() 函数
描述 hypot() 返回欧几里德范数 sqrt(x*x + y*y). 语法 以下是 hypot() 方法的语法: import math math.hypot(x, y) 注意:hypot()是不 ...
- 如何设置Docker容器中Java应用的内存限制
如果使用官方的Java镜像,或者基于Java镜像构建的Docker镜像,都可以通过传递 JAVA_OPTS 环境变量来轻松地设置JVM的内存参数.比如,对于官方Tomcat 镜像,我们可以执行下面命令 ...