-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.min.js
More file actions
1 lines (1 loc) · 5.82 KB
/
Copy pathscripts.min.js
File metadata and controls
1 lines (1 loc) · 5.82 KB
1
!function(){const e=window.matchMedia("(pointer: coarse)").matches,t=window.matchMedia("(prefers-reduced-motion: reduce)").matches,n=document.getElementById("stage");if(!n)return;n.setAttribute("data-cursor",e?"off":"on");const o=document.querySelector(".va-hero"),r=o&&o.querySelector("h1.va-h1");o&&(o.classList.add("pre"),r&&r.classList.add("pre"),requestAnimationFrame(()=>requestAnimationFrame(()=>{o.classList.remove("pre"),r&&r.classList.remove("pre")})),setTimeout(()=>{o.classList.remove("pre"),r&&r.classList.remove("pre")},2500));const i={x:window.innerWidth/2,y:window.innerHeight/2,active:!1},s=document.querySelector(".va-orb-1"),a=document.querySelector(".va-orb-2"),c=document.getElementById("va-cursor"),l=document.getElementById("va-cursor-ring");let d=i.x,u=i.y,m=!1,h=null;function v(){m=!1;const e=window.innerWidth,t=window.innerHeight,n=2*(i.x/e-.5),o=2*(i.y/t-.5);s&&(s.style.transform=`translate3d(${40*n}px, ${40*o}px, 0)`),a&&(a.style.transform=`translate3d(${30*-n}px, ${30*-o}px, 0)`),c&&(c.style.transform=`translate3d(${i.x}px, ${i.y}px, 0) translate(-50%, -50%)`),l&&!h&&(h=requestAnimationFrame(y))}function y(){d+=.18*(i.x-d),u+=.18*(i.y-u),l.style.transform=`translate3d(${d}px, ${u}px, 0) translate(-50%, -50%)`,h=Math.abs(i.x-d)>.4||Math.abs(i.y-u)>.4?requestAnimationFrame(y):null}if(!e&&(window.addEventListener("mousemove",e=>{i.x=e.clientX,i.y=e.clientY,i.active=!0,m||(m=!0,requestAnimationFrame(v))},{passive:!0}),c&&l)){const A="a, button, .va-proj, .va-stack-item, .va-hobby";document.querySelectorAll(A).forEach(e=>{e.addEventListener("mouseenter",()=>l.classList.add("hover")),e.addEventListener("mouseleave",()=>l.classList.remove("hover"))}),window.addEventListener("mousedown",()=>l.classList.add("click")),window.addEventListener("mouseup",()=>l.classList.remove("click"))}const p=document.getElementById("va-canvas");if(!p||e||t)p&&(p.style.display="none");else{const S=p.getContext("2d"),$=1;let I=0,C=0;function f(){I=p.width=window.innerWidth*$,C=p.height=window.innerHeight*$,p.style.width=window.innerWidth+"px",p.style.height=window.innerHeight+"px"}f(),window.addEventListener("resize",f);const M=[{x:.3*I,y:.3*C,r:280,vx:.6,vy:.4,c:"96,165,250",phase:0},{x:.7*I,y:.4*C,r:340,vx:-.5,vy:.7,c:"167,139,250",phase:2},{x:.5*I,y:.7*C,r:300,vx:.4,vy:-.5,c:"139,92,246",phase:4},{x:.2*I,y:.8*C,r:260,vx:.7,vy:-.3,c:"59,130,246",phase:1}];let F=I/2,B=C/2,O=0,T=null,k=!0,R=!0;function g(){F+=.06*(i.x*$-F),B+=.06*(i.y*$-B),S.clearRect(0,0,I,C),S.globalCompositeOperation="lighter";for(let e=0;e<M.length;e++){const t=M[e];t.x+=t.vx+.3*Math.sin(.5*O+t.phase),t.y+=t.vy+.3*Math.cos(.4*O+t.phase),t.x+=.002*(F-t.x),t.y+=.002*(B-t.y),t.x<-t.r?t.x=I+t.r:t.x>I+t.r&&(t.x=-t.r),t.y<-t.r?t.y=C+t.r:t.y>C+t.r&&(t.y=-t.r);const n=t.r+40*Math.sin(O+t.phase),o=S.createRadialGradient(t.x,t.y,0,t.x,t.y,n);o.addColorStop(0,`rgba(${t.c},0.32)`),o.addColorStop(.5,`rgba(${t.c},0.07)`),o.addColorStop(1,`rgba(${t.c},0)`),S.fillStyle=o,S.beginPath(),S.arc(t.x,t.y,n,0,2*Math.PI),S.fill()}S.globalCompositeOperation="source-over",O+=.01,T=requestAnimationFrame(g)}function w(){!T&&k&&R&&(T=requestAnimationFrame(g))}function x(){T&&(cancelAnimationFrame(T),T=null)}w(),document.addEventListener("visibilitychange",()=>{R=!document.hidden,R?w():x()}),o&&"IntersectionObserver"in window&&new IntersectionObserver(e=>{k=e[0].isIntersecting,k?w():x()},{threshold:0}).observe(o)}function b(e){let t=null,n=null;return function(o){n=o,t||(t=requestAnimationFrame(()=>{t=null,e.call(this,n)}))}}e||(document.querySelectorAll(".va-proj").forEach(e=>{e.addEventListener("mousemove",b(function(t){const n=e.getBoundingClientRect(),o=(t.clientX-n.left)/n.width-.5,r=(t.clientY-n.top)/n.height-.5;e.style.transform=`perspective(1200px) rotateX(${4*-r}deg) rotateY(${4*o}deg) translateY(-4px)`}),{passive:!0}),e.addEventListener("mouseleave",()=>{e.style.transform=""})}),document.querySelectorAll(".va-stack-item").forEach(e=>{e.addEventListener("mousemove",b(function(t){const n=e.getBoundingClientRect();e.style.setProperty("--mx",(t.clientX-n.left)/n.width*100+"%"),e.style.setProperty("--my",(t.clientY-n.top)/n.height*100+"%")}),{passive:!0})}),document.querySelectorAll("[data-magnetic]").forEach(e=>{e.addEventListener("mousemove",b(function(t){const n=e.getBoundingClientRect(),o=t.clientX-n.left-n.width/2,r=t.clientY-n.top-n.height/2;e.style.transform=`translate(${.25*o}px, ${.25*r}px)`}),{passive:!0}),e.addEventListener("mouseleave",()=>{e.style.transform=""})}));const E=document.querySelectorAll("[data-section]"),L=document.querySelectorAll(".va-dot");if(L.forEach(e=>e.addEventListener("click",()=>{const t=document.querySelector(`[data-section="${e.dataset.target}"]`);t&&window.scrollTo({top:t.offsetTop-80,behavior:"smooth"})})),E.length&&"IntersectionObserver"in window){const Y=new IntersectionObserver(e=>{e.forEach(e=>{if(e.isIntersecting){const t=e.target.dataset.section;L.forEach(e=>e.classList.toggle("active",e.dataset.target===t))}})},{rootMargin:"-40% 0px -50% 0px"});E.forEach(e=>Y.observe(e))}function q(e){if(e._counted)return;e._counted=!0;const t=+e.dataset.count,n=performance.now();requestAnimationFrame(function o(r){const i=Math.min(1,(r-n)/1400),s=1-Math.pow(1-i,3);e.textContent=Math.round(t*s).toString(),i<1?requestAnimationFrame(o):e.textContent=t.toString()})}document.querySelectorAll("[data-count]").forEach(e=>{if(e.textContent="0",function(e){const t=e.getBoundingClientRect();return t.top<window.innerHeight&&t.bottom>0}(e))setTimeout(()=>q(e),200);else if("IntersectionObserver"in window){const t=new IntersectionObserver(n=>{n[0].isIntersecting&&(q(e),t.disconnect())},{threshold:.1});t.observe(e)}setTimeout(()=>q(e),2e3)}),document.addEventListener("click",e=>{const t=e.target.closest('a[href^="#"]');if(!t)return;const n=t.getAttribute("href");if(n.length<=1)return;const o=document.querySelector(n);o&&(e.preventDefault(),window.scrollTo({top:o.offsetTop-80,behavior:"smooth"}))})}();