mirror of
https://ghfast.top/https://github.com/zsjy/halo-theme-dream2.0-plus.git
synced 2025-03-15 02:43:08 +08:00
1 line
1.6 KiB
JavaScript
1 line
1.6 KiB
JavaScript
!function(){let i,e,n=void 0,t=(n,document.body),o=window.innerWidth,s=window.innerHeight,h={x:o/2,y:o/2},a=[],l=[];function d(i){if(0<i.touches.length)for(let t=0;t<i.touches.length;t++)c(i.touches[t].clientX,i.touches[t].clientY,l[Math.floor(Math.random()*l.length)])}function c(t,i,e){a.push(new r(t,i,e))}function r(t,i,e){var n=Math.floor(60*Math.random()+60);this.initialLifeSpan=n,this.lifeSpan=n,this.velocity={x:(Math.random()<.5?-1:1)*(Math.random()/10),y:-1*Math.random()-.4},this.position={x:t,y:i},this.canv=e,this.baseDimension=4,this.update=function(t){this.position.x+=this.velocity.x,this.position.y+=this.velocity.y,this.velocity.x+=2*(Math.random()<.5?-1:1)/75,this.velocity.y-=Math.random()/600,this.lifeSpan--;var i=.2+(this.initialLifeSpan-this.lifeSpan)/this.initialLifeSpan;t.fillStyle="#e6f1f7",t.strokeStyle="#3a92c5",t.beginPath(),t.arc(this.position.x-this.baseDimension/2*i,this.position.y-this.baseDimension/2,this.baseDimension*i,0,2*Math.PI),t.stroke(),t.fill(),t.closePath()}}i=document.createElement("canvas"),e=i.getContext("2d"),i.style.top="0px",i.style.left="0px",i.style.pointerEvents="none",n,i.style.position="fixed",document.body.appendChild(i),i.width=o,i.height=s,t.addEventListener("mousemove",function(t){n,h.x=t.clientX,h.y=t.clientY,c(h.x,h.y)}),t.addEventListener("touchmove",d,{passive:!0}),t.addEventListener("touchstart",d,{passive:!0}),window.addEventListener("resize",function(t){o=window.innerWidth,s=window.innerHeight,n,i.width=o,i.height=s}),function t(){e.clearRect(0,0,o,s);for(let t=0;t<a.length;t++)a[t].update(e);for(let t=a.length-1;0<=t;t--)a[t].lifeSpan<0&&a.splice(t,1);requestAnimationFrame(t)}()}(); |