之前介绍了好几款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实现五彩小圆圈背景特效的更多相关文章

  1. 一款基于HTML5 Canvas的画板涂鸦动画

    今天给各网友分享一款基于HTML5 Canvas的画板涂鸦动画.记得之前我们分享过一款HTML5 Canvas画板工具,可以切换不同的笔刷,功能十分强大.本文今天要再来分享一款基于HTML5 Canv ...

  2. 基于HTML5 Canvas实现的图片马赛克模糊特效

    效果请点击下面网址: http://hovertree.com/texiao/html5/1.htm 一.开门见山受美国肖像画家Chuck Close的启发,此脚本通过使用HTML5 canvas元素 ...

  3. HTML5 Canvas 奔跑的小狗

    效果如上图,共六个图像切换,形成小狗动态奔跑效果.完整代码和图片请从  https://files.cnblogs.com/files/xiandedanteng/runningDog.rar 下载. ...

  4. 4款基于html5 canvas充满想象力的重力特效

    今天给大家分享4个物理和重力实验,用来展示 html canvas 的强大.几年前,所有这些实验都必须使用 Java 或 Flash 才能做.在下面这些惊人的例子中,就个人而言,我比较喜欢仿真布料的那 ...

  5. smoke.js是一款基于HTML5 Canvas的逼真烟雾特效js插件。通过该js插件,可以非常轻松的在页面中制作出各种烟雾效果。

    Smoke.js 是一个浏览器默认警告系统的JavaScript替代品,如果你想要跨浏览器与平台的标准化JavaScript警告窗口,Smoke.js就是你想要的. Smoke.js是一个轻量级且灵活 ...

  6. 程序猿必备的10款超炫酷HTML5 Canvas插件

    1.超炫酷HTML5 Canvas 3D旋转地球动画 这是一款基于HTML5 Canvas的3D地球模拟动画,动画以太空作为背景,地球在太空中旋转,同时我们也可以拖拽鼠标来从不同的角度观察地球.另外我 ...

  7. 9款基于HTML5/SVG/Canvas的折线图表应用

    1.华丽的HTML5图表 可展示实时数据 HTML5在图表应用中也十分广泛,比起以前的网页图表,HTML5图表制作更便捷,功能更强大.这款HTML5图表插件外观十分华丽和专业,在数据展示方面也很有优势 ...

  8. 16个富有创意的HTML5 Canvas动画特效集合

    HTML5技术正在不断的发展和更新,越来越多的开发者也正在加入HTML5阵营,甚至在移动开发上HTML5的地位也是越来越重要了.HTML5中的大部分动画都是通过Canvas实现,因为Canvas就像一 ...

  9. 16个非常有趣的HTML5 Canvas动画特效集合

    HTML5技术正在不断的发展和更新,越来越多的开发者也正在加入HTML5阵营,甚至在移动开发上HTML5的地位也是越来越重要了.HTML5中的大部分动画都是通过Canvas实现,因为Canvas就像一 ...

随机推荐

  1. 用 Qt Creator 开发非 Qt 的 C/C++ 程序

    在Windows还是习惯用VS2005但是现在到了Linux下,开发起来C/C++程序就没有那么得心应手的IDE了.虽然很多人推荐E开头那个主要作为Java开发的IDE,不过安上插件后感觉不大好,一个 ...

  2. 国内四大炒股软件APP 全面技术解析

    随着人们的焦点逐步由电脑PC端转为手机端之后,国内炒股软件也逐步开始推出手机炒股APP,但是面对如此众多的都以“最牛.最佳”等冠名的APP真的实至名归吗?为了大家不再走弯路,不沉迷智能选股,笔者将近期 ...

  3. 原创:微信小程序调用PHP后台接口,解析纯html文本

    ---效果图片预览---    1.微信js动态传参:wx.request({        url: 'https://m.****.com/index.php/Home/Xiaoxxf/activ ...

  4. Archlive新年第一棒: 基于2.6.37稳定内核的archlive20110107

    先上图,再来说明吧... 下载地址: http://u.115.com/file/t2cd0ea120 先上个本机器运行teamviewer的效果图吧... 如假包换的 2.6.37,  担保是目前最 ...

  5. cxf之Exception in thread "main" java.lang.NoSuchMethodError: org.apache.cxf.jaxrs.provider.ProviderFactory.<init>(Lorg/apache/cxf/Bus;)V

    pom.xml中关于cxf的配置jar包冲突??? 1.http://blog.csdn.net/yzl_8877/article/details/53216923 2.https://www.cnb ...

  6. 【LeetCode】37. Sudoku Solver

    Sudoku Solver Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are i ...

  7. 套接字I/O超时设置方法和用select实现超时

    注:如无特殊说明,sockfd 原始状态都是阻塞的. 一.使用alarm 函数设置超时  C++ Code  1 2 3 4 5 6 7 8 9 10 11 12 13   void handler( ...

  8. Linux内核(11) - 子系统的初始化之内核选项解析

    首先感谢国家.其次感谢上大的钟莉颖,让我知道了大学不仅有校花,还有校鸡,而且很多时候这两者其实没什么差别.最后感谢清华女刘静,让我深刻体会到了素质教育的重要性,让我感到有责任写写子系统的初始化. 各个 ...

  9. Win2008 r2 IIS7.5出现FastCGI进程最近常常失败。请过一会再尝试此请求的解决方法

    错误信息如图所示: 应用程序“PIAOYUN.CC”中的服务器错误Internet Information Services 7.5 错误摘要HTTP 错误 500.0 - Internal Serv ...

  10. JAVA多线程和并发基础面试问答【转】

    JAVA多线程和并发基础面试问答 多线程和并发问题是Java技术面试中面试官比较喜欢问的问题之一.在这里,从面试的角度列出了大部分重要的问题,但是你仍然应该牢固的掌握Java多线程基础知识来对应日后碰 ...