2023-03-21 10:49:35 +08:00

1 line
1.5 KiB
JavaScript

(()=>{var f;(f=jQuery).fn.circleMagic=function(e){let t,n,o,a,r=!0;const i=[],d=f.extend({color:"rgba(255,255,255,.5)",radius:10,density:.3,clearOffset:.2,mode:"all"},e);var c,e=this[0];function s(){const e=document.documentElement.classList.contains("night");if(("all"===d.mode||"day"===d.mode&&!e||"night"===d.mode&&e)&&r){a.clearRect(0,0,t,n);for(const e in i)i[e].draw()}requestAnimationFrame(s)}function l(){var e=this;function o(){e.pos.x=Math.random()*t,e.pos.y=n+100*Math.random(),e.alpha=.1+Math.random()*d.clearOffset,e.scale=.1+.3*Math.random(),e.speed=Math.random(),"random"===d.color?e.color="rgba("+Math.floor(255*Math.random())+", "+Math.floor(255*Math.random())+", "+Math.floor(255*Math.random())+", "+Math.random().toPrecision(2)+")":e.color=d.color}e.pos={},o(),this.draw=function(){e.alpha<=0&&o(),e.pos.y-=e.speed,e.alpha-=5e-4,a.beginPath(),a.arc(e.pos.x,e.pos.y,e.scale*d.radius,0,2*Math.PI,!1),a.fillStyle=e.color,a.fill(),a.closePath()}}t=window.innerWidth,n=window.innerHeight,(o=((c=document.createElement("canvas")).setAttribute("class","canvas_effects "+d.mode),e.prepend(c),c)).width=t,o.height=n,a=o.getContext("2d");for(let e=0;e<t*d.density;e++){var h=new l;i.push(h)}s(),window.addEventListener("scroll",function(){r=!(document.body.scrollTop>n)},!1),window.addEventListener("resize",function(){t=window.innerWidth,n=window.innerHeight,o.width=t,o.height=n},!1)},f("body").circleMagic({radius:35,density:.3,color:"rgba(255,255,255, .4)",clearOffset:.3,mode:DreamConfig.effects_circle_magic_mode})})();