、简介
Canvas-nest.js是一个非常好看的网页粒子背景插件,不需要依赖任何第三方库即可运行,提供额非常炫酷的背景。
2、特点
不依赖于任何框架或者库,使用原生js编写。轻量级,只有不到2kb(50行代码左右)。使用起来非常简单,直接在html页面引入即可。
3、使用方法
直接把下面这段代码粘贴到HTML的body标签中即可
<
script
type
=
"text/javascript"
src
=
"canvas-nest.js"
>
script
>
注:不要把上面代码放到head标签之类,否则不会生效。
4、自定义外观
在script中加入相应的参数,自定义参数值即可,如下:
<
script
type
=
"text/javascript"
color
=
"255,0,0"
opacity
=
"0.5"
count
=
"99"
src
=
"canvas-nest.js"
>
script
>
参数说明:
color="255,0,0"
背景粒子线的颜色
opacity
=
"0.5" 背景粒子线的透明度,一般设置成0.5-1之间
count
=
"99" 背景粒子线的密度,建议不要太大,否则页面容易卡死
另附官网地址:http://www.atool.org/
canvas-nest.js源码如下:
/**
* Copyright (c) 2016 hustcc
* License: MIT
* Version: v1.0.1
* GitHub: https://github.com/hustcc/canvas-nest.js
**/
!function(){function n(n,e,t){return n.getAttribute(e)||t}function e(n){return document.getElementsByTagName(n)}function t(){var t=e("script"),o=t.length,i=t[o-1];return{l:o,z:n(i,"zIndex",-1),o:n(i,"opacity",.5),c:n(i,"color","0,0,0"),n:n(i,"count",99)}}function o(){a=m.width=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,c=m.height=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight}function i(){r.clearRect(0,0,a,c);var n,e,t,o,m,l;s.forEach(function(i,x){for(i.x+=i.xa,i.y+=i.ya,i.xa*=i.x>a||i.x<0?-1:1,i.ya*=i.y>c||i.y<0?-1:1,r.fillRect(i.x-.5,i.y-.5,1,1),e=x+1;e