halo-theme-dream2.0-plus/source/js/cursor/move/springyEmojiCursor.min.js
2023-03-21 10:49:35 +08:00

1 line
2.3 KiB
JavaScript

!function(){let n,o,t,e=void 0,s=(e,document.body),c=10,h=10,y=window.innerWidth,l=window.innerHeight,a={x:y/2,y:y/2},d=[];function v(i){y=window.innerWidth,l=window.innerHeight,e,n.width=y,n.height=l}function x(i){0<i.touches.length&&(e,a.x=i.touches[0].clientX,a.y=i.touches[0].clientY)}function r(i){e,a.x=i.clientX,a.y=i.clientY}function p(){for(n.width=n.width,d[0].position.x=a.x,d[0].position.y=a.y,i=1;i<7;i++){var t=new w(0,0);0<i&&u(i-1,i,t),i<6&&u(i+1,i,t);var e=new w(10*-d[i].velocity.x,10*-d[i].velocity.y),t=new w(+(t.X+e.X),+(t.Y+e.Y)+50);d[i].velocity.x+=.01*t.X,d[i].velocity.y+=.01*t.Y,Math.abs(d[i].velocity.x)<.1&&Math.abs(d[i].velocity.y)<.1&&Math.abs(t.X)<.1&&Math.abs(t.Y)<.1&&(d[i].velocity.x=0,d[i].velocity.y=0),d[i].position.x+=d[i].velocity.x,d[i].position.y+=d[i].velocity.y,e=n.clientHeight,t=n.clientWidth,d[i].position.y>=e-11-1&&(0<d[i].velocity.y&&(d[i].velocity.y=.7*-d[i].velocity.y),d[i].position.y=e-11-1),d[i].position.x>=t-11&&(0<d[i].velocity.x&&(d[i].velocity.x=.7*-d[i].velocity.x),d[i].position.x=t-11-1),d[i].position.x<0&&(d[i].velocity.x<0&&(d[i].velocity.x=.7*-d[i].velocity.x),d[i].position.x=0),d[i].draw(o)}requestAnimationFrame(p)}function w(i,t){this.X=i,this.Y=t}function u(i,t,e){var n,o=d[i].position.x-d[t].position.x,i=d[i].position.y-d[t].position.y,t=Math.sqrt(o*o+i*i);t>c&&(n=h*(t-c),e.X+=o/t*n,e.Y+=i/t*n)}function f(i){this.position={x:a.x,y:a.y},this.velocity={x:0,y:0},this.canv=i,this.draw=function(i){i.drawImage(this.canv,this.position.x-this.canv.width/2,this.position.y-this.canv.height/2,this.canv.width,this.canv.height)}}{n=document.createElement("canvas"),o=n.getContext("2d"),n.style.top="0px",n.style.left="0px",n.style.pointerEvents="none",e,n.style.position="fixed",document.body.appendChild(n),n.width=y,n.height=l,o.font="16px serif",o.textBaseline="middle",o.textAlign="center";var g=o.measureText("🤪"),m=document.createElement("canvas"),X=m.getContext("2d");m.width=g.width,m.height=2*g.actualBoundingBoxAscent,X.textAlign="center",X.font="16px serif",X.textBaseline="middle",X.fillText("🤪",m.width/2,g.actualBoundingBoxAscent),t=m;let i=0;for(i=0;i<7;i++)d[i]=new f(t);s.addEventListener("mousemove",r),s.addEventListener("touchmove",x,{passive:!0}),s.addEventListener("touchstart",x,{passive:!0}),window.addEventListener("resize",v),p()}}();