Sonic.js 是一个很小的 JavaScript 类,用于创建基于 HTML5 画布的加载图像。更强大的是 Sonic.js 还提供了基于现成的例子的创建工具,可以帮助你实现更多自定义的(Loading)加载动画效果。

在线预览   源码下载

实现的代码。

html代码:

 var loaders = [

    {

        width: 100,
height: 50,
padding: 10, stepsPerFrame: 2,
trailLength: 1,
pointDistance: .03, strokeColor: '#FF7B24', step: 'fader', multiplier: 2, setup: function () {
this._.lineWidth = 5;
}, path: [ ['arc', 10, 10, 10, -270, -90],
['bezier', 10, 0, 40, 20, 20, 0, 30, 20],
['arc', 40, 10, 10, 90, -90],
['bezier', 40, 0, 10, 20, 30, 0, 20, 20]
]
}, { width: 30,
height: 30, stepsPerFrame: 2,
trailLength: .3,
pointDistance: .1,
padding: 10, fillColor: '#D4FF00',
strokeColor: '#FFF', setup: function () {
this._.lineWidth = 20;
}, path: [
['line', 0, 0, 30, 0],
['line', 30, 0, 30, 30],
['line', 30, 30, 0, 30],
['line', 0, 30, 0, 0]
]
}, { width: 100,
height: 100, stepsPerFrame: 1,
trailLength: 1,
pointDistance: .025, strokeColor: '#05E2FF', fps: 20, setup: function () {
this._.lineWidth = 2;
},
step: function (point, index) { var cx = this.padding + 50,
cy = this.padding + 50,
_ = this._,
angle = (Math.PI / 180) * (point.progress * 360); this._.globalAlpha = Math.max(.5, this.alpha); _.beginPath();
_.moveTo(point.x, point.y);
_.lineTo(
(Math.cos(angle) * 35) + cx,
(Math.sin(angle) * 35) + cy
);
_.closePath();
_.stroke(); _.beginPath();
_.moveTo(
(Math.cos(-angle) * 32) + cx,
(Math.sin(-angle) * 32) + cy
);
_.lineTo(
(Math.cos(-angle) * 27) + cx,
(Math.sin(-angle) * 27) + cy
);
_.closePath();
_.stroke(); },
path: [
['arc', 50, 50, 40, 0, 360]
]
}, { width: 100,
height: 50, stepsPerFrame: 1,
trailLength: 1,
pointDistance: .1,
fps: 15,
padding: 10,
//step: 'fader', fillColor: '#FF2E82', setup: function () {
this._.lineWidth = 20;
}, path: [
['line', 0, 20, 100, 20],
['line', 100, 20, 0, 20]
]
}, { width: 100,
height: 100, stepsPerFrame: 7,
trailLength: .7,
pointDistance: .01,
fps: 30, setup: function () {
this._.lineWidth = 10;
}, path: [
['line', 20, 70, 50, 20],
['line', 50, 20, 80, 70],
['line', 80, 70, 20, 70]
]
}, { width: 100,
height: 100, stepsPerFrame: 4,
trailLength: 1,
pointDistance: .01,
fps: 25, fillColor: '#FF7B24', setup: function () {
this._.lineWidth = 10;
}, step: function (point, i, f) { var progress = point.progress,
degAngle = 360 * progress,
angle = Math.PI / 180 * degAngle,
angleB = Math.PI / 180 * (degAngle - 180),
size = i * 5; this._.fillRect(
Math.cos(angle) * 25 + (50 - size / 2),
Math.sin(angle) * 15 + (50 - size / 2),
size,
size
); this._.fillStyle = '#63D3FF'; this._.fillRect(
Math.cos(angleB) * 15 + (50 - size / 2),
Math.sin(angleB) * 25 + (50 - size / 2),
size,
size
); if (point.progress == 1) { this._.globalAlpha = f < .5 ? 1 - f : f; this._.fillStyle = '#EEE'; this._.beginPath();
this._.arc(50, 50, 5, 0, 360, 0);
this._.closePath();
this._.fill(); } }, path: [
['line', 40, 10, 60, 90]
]
}, { width: 100,
height: 100, stepsPerFrame: 3,
trailLength: 1,
pointDistance: .01,
fps: 30,
step: 'fader', strokeColor: '#D4FF00', setup: function () {
this._.lineWidth = 6;
}, path: [
['arc', 50, 50, 20, 360, 0]
]
}, { width: 100,
height: 100, stepsPerFrame: 1,
trailLength: 1,
pointDistance: .02,
fps: 30, fillColor: '#05E2FF', step: function (point, index) { this._.beginPath();
this._.moveTo(point.x, point.y);
this._.arc(point.x, point.y, index * 7, 0, Math.PI * 2, false);
this._.closePath();
this._.fill(); }, path: [
['arc', 50, 50, 30, 0, 360]
] }, { width: 100,
height: 100, stepsPerFrame: 1,
trailLength: 1,
pointDistance: .05, strokeColor: '#FF2E82', fps: 20, setup: function () {
this._.lineWidth = 4;
},
step: function (point, index) { var cx = this.padding + 50,
cy = this.padding + 50,
_ = this._,
angle = (Math.PI / 180) * (point.progress * 360),
innerRadius = index === 1 ? 10 : 25; _.beginPath();
_.moveTo(point.x, point.y);
_.lineTo(
(Math.cos(angle) * innerRadius) + cx,
(Math.sin(angle) * innerRadius) + cy
);
_.closePath();
_.stroke(); },
path: [
['arc', 50, 50, 40, 0, 360]
]
} ]; var d, a, container = document.getElementById('in'); for (var i = -1, l = loaders.length; ++i < l; ) { d = document.createElement('div');
d.className = 'l'; a = new Sonic(loaders[i]); d.appendChild(a.canvas);
container.appendChild(d); a.canvas.style.marginTop = (150 - a.fullHeight) / 2 + 'px';
a.canvas.style.marginLeft = (150 - a.fullWidth) / 2 + 'px'; a.play(); }

via:http://www.w2bc.com/Article/26212

基于HTML5 Canvas 实现的 Loading 效果的更多相关文章

  1. 基于HTML5 Canvas可撕裂布料效果

    分享一款布料效果的 HTML5 Canvas 应用演示,效果逼真.你会看到,借助 Canvas 的强大绘图和动画功能,只需很少的代码就能实现让您屏息凝神的效果. 在线预览   源码下载 实现的代码. ...

  2. 基于HTML5 Canvas粒子效果文字动画特效

    之前我们分享过很多超酷的文字特效,其中也有利用HTML5和CSS3的.今天我们要来分享一款基于HTML5 Canvas的文字特效,输入框中输入想要展示的文字,回车后即可在canvas上绘制出粒子效果的 ...

  3. 基于HTML5 Canvas生成粒子效果的人物头像

    前面我们分享过一个HTML5 Canvas实现的图像马赛克模糊效果,HTML5处理图片真的非常简单.今天我们要再利用HTML5 Canvas实现一个粒子效果的人物头像,你可以任意选择一张头像图片,接下 ...

  4. 超酷!!HTML5 Canvas 水流样式 Loading 动画

    今天我们要分享另外一款基于HTML5 Canvas的液体流动样式Loading加载动画,这款Loading动画在加载时会呈现液体流动的动画效果,并且由于和背景颜色的对比,也略微呈现发光的动画效果. 效 ...

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

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

  6. 基于html5 canvas和js实现的水果忍者网页版

    今天爱编程小编给大家分享一款基于html5 canvas和js实现的水果忍者网页版. <水果忍者>是一款非常受喜欢的手机游戏,刚看到新闻说<水果忍者>四周年新版要上线了.网页版 ...

  7. 基于 HTML5 Canvas 的智能安防 SCADA 巡逻模块

    基于 HTML5 Canvas 的智能安防 SCADA 巡逻模块 前言 最近学习了 HT for Web flow 插件,除了正常的 flow 效果,其中还有两个十分好用的两个接口 getPercen ...

  8. 基于HTML5 Canvas和jQuery 的绘图工具的实现

    简单介绍 HTML5 提供了强大的Canvas元素.使用Canvas并结合Javascript 能够实现一些很强大的功能.本文就介绍一下基于HTML5 Canvas 的绘图工具的实现.废话少说,先看成 ...

  9. 18个基于 HTML5 Canvas 开发的图表库

    如今,HTML5 可谓如众星捧月一般,受到许多业内巨头的青睐.很多Web开发者也尝试着用 HTML 5 来制作各种各样的富 Web 应用.HTML 5 规范引进了很多新特性,其中之一就是 Canvas ...

随机推荐

  1. hybrid app开发中用到的html5新特性localStorage、sessionStorage和websql database

    近期在项目中进行hybrid app开发,项目中有大量的js代码执行在android设备上. 使用到了非常多HTML5的新特性,之前没有遇到过,不了解.这里记录下添加点前端的知识.混合式app开发中. ...

  2. 【转】 Python 中,matplotlib绘图无法显示中文的问题

    在python中,默认情况下是无法显示中文的,如下代码: import matplotlib.pyplot as plt # 定义文本框和箭头格式 decisionNode = dict(boxsty ...

  3. 嵌入式 如何定位死循环或高CPU使用率(linux)

    如何定位死循环或高CPU使用率(linux)  确定是CPU过高 使用top观察是否存在CPU使用率过高现象 找出线程 对CPU使用率过高的进程的所有线程进行排序 ps H -e -o pid,tid ...

  4. HDU 1595 find the longest of the shortest【次短路】

    转载请注明出处:http://blog.csdn.net/a1dark 分析:经典的次短路问题.dijkstra或者SPFA都能做.先找出最短路.然后依次删掉没条边.为何正确就不证明了.了解思想直接A ...

  5. ARC下 does not support automated __weak references错误

    ARC下 does not support automated __weak references错误 此错误,通常是你的ARC下不支持weak 把你项目里面,weak的地方 改为 unsafe_un ...

  6. android中的byte数组转换(转)

    /** * 将一个单字节的byte转换成32位的int * * @param b * byte * @return convert result */ public static int unsign ...

  7. 在linux下新增一块硬盘的操作。(包含大于2T的硬盘在linux下挂载操作)

    转自:http://blog.csdn.net/season_hangzhou/article/details/36423223 一.安装硬盘到物理机上. 二.查看硬盘是否正确安装. 使用“fdisk ...

  8. oracle导出数据库dmp文件

    导出数据库为dmp文件,按照当前导出时间设置文件名称 @ECHO OFF ECHO 备份 SCOTT 用户的数据…… SET DBUserName=scott SET DBPassword= SET ...

  9. Ubuntu 14.04安装配置NFS

    (一)安装NFS服务器 sudo apt-get install nfs-kernel-server sudo apt-get install nfs-common​(在安装nsf-kernel-se ...

  10. beyond compare 与git diff整合

    这两天花了点时间最终在Window和Mac上把Beyong Compare和git整合好.当中遇到到非常多坑,如今把这些都分享出来.希望对大家有帮助. 首先如果你已经装好了Beyong Compare ...