背景线条实现

2022-10-17,

!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<u.length;e++)n=u[e],
 
null!==n.x&&null!==n.y&&(o=i.x-n.x,m=i.y-n.y,
 
l=o*o+m*m,l<n.max&&(n===y&&l>=n.max/2&&(i.x-=.03*o,i.y-=.03*m),
 
t=(n.max-l)/n.max,r.beginpath(),r.linewidth=t/2,r.strokestyle="rgba("+d.c+","+(t+.2)+")",r.moveto(i.x,i.y),r.lineto(n.x,n.y),r.stroke()))
 
}),
 
x(i)
 
}
 
var a,c,u,m=document.createelement("canvas"),
 
d=t(),l="c_n"+d.l,r=m.getcontext("2d"),
 
x=window.requestanimationframe||window.webkitrequestanimationframe||window.mozrequestanimationframe||window.orequestanimationframe||window.msrequestanimationframe||
 
function(n){
 
window.settimeout(n,1e3/45)
 
},
 
w=math.random,y={x:null,y:null,max:2e4};m.id=l,m.style.csstext="position:fixed;top:0;left:0;z-index:"+d.z+";opacity:"+d.o,e("body")[0].appendchild(m),o(),window.onresize=o,
 
window.onmousemove=function(n){
 
n=n||window.event,y.x=n.clientx,y.y=n.clienty
 
},
 
window.onmouseout=function(){
 
y.x=null,y.y=null
 
};
 
for(var s=[],f=0;d.n>f;f++){
 
var h=w()*a,g=w()*c,v=2*w()-1,p=2*w()-1;s.push({x:h,y:g,xa:v,ya:p,max:6e3})
 
}
 
u=s.concat([y]),
 
settimeout(function(){i()},100)
 
}()

 

原文:

《背景线条实现.doc》

下载本文的Word格式文档,以方便收藏与打印。