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

最新文章

  1. SolrCloud 5.x 集群部署方法
  2. java ConcurrentModificationException探究
  3. html释疑
  4. Helpers\TableBuilder
  5. Oracle的instr函数
  6. Java公开课-06.单例
  7. phpstudy 配置端口 和 虚拟域名访问
  8. 前端图片缓存之通过img标签加载GIF只能播放一次问题(转载)
  9. 5、在Dreamweaver cc 2017中添加服务器扩展组件
  10. JAVA 第九周学习总结
  11. job.yml
  12. java对文件操作之实用
  13. asp.net cookie的操作
  14. python-面向对象-10-单例
  15. Could NOT find SDL_image (missing:SDL_IMAGE_LIBRARIES SDL_IMAGE_INCLUDE_DIRS)
  16. linux - fpga-framebuff驱动
  17. JavaScript &amp; jQuery Code Snippet
  18. Yii: 扩展CGridView增加导出CSV功能
  19. ubuntu 防止软件包自动更新
  20. 【BZOJ4704】旅行 树链剖分+可持久化线段树

热门文章

  1. 如何获得Windows Server 2012上的FC的WWN
  2. Nicescroll滚动条插件的用法
  3. docker下搭建gitlab
  4. 想控制GIF图片动画播放吗?试试gifffer.js
  5. nginx的 CPU參数worker_processes和worker_cpu_affinity使用说明
  6. T-SQL 之 视图
  7. SQL语法 之 操作语句
  8. [原创-性能调优]借助AWR报告分析解决oracleCPU过高的问题
  9. UVA - 10162 Last Digit
  10. Spring MVC 中Ajax返回字符串