Repository navigation
Expand file tree
/
Copy pathscripts.min.js
More file actions
1 lines (1 loc) · 5.2 KB
/
Copy pathscripts.min.js
File metadata and controls
1 lines (1 loc) · 5.2 KB
1
!function(){const e=window.matchMedia("(pointer: coarse)").matches,t=window.matchMedia("(prefers-reduced-motion: reduce)").matches;if(!document.getElementById("stage"))return;const n=document.querySelector(".va-hero"),o=n&&n.querySelector("h1.va-h1");n&&(n.classList.add("pre"),o&&o.classList.add("pre"),requestAnimationFrame(()=>requestAnimationFrame(()=>{n.classList.remove("pre"),o&&o.classList.remove("pre")})),setTimeout(()=>{n.classList.remove("pre"),o&&o.classList.remove("pre")},2500));const r={x:window.innerWidth/2,y:window.innerHeight/2},i=document.querySelector(".va-orb-1"),s=document.querySelector(".va-orb-2");let a=!1;function c(){a=!1;const e=2*(r.x/window.innerWidth-.5),t=2*(r.y/window.innerHeight-.5);i&&(i.style.transform=`translate3d(${40*e}px, ${40*t}px, 0)`),s&&(s.style.transform=`translate3d(${30*-e}px, ${30*-t}px, 0)`)}e||window.addEventListener("mousemove",e=>{r.x=e.clientX,r.y=e.clientY,a||(a=!0,requestAnimationFrame(c))},{passive:!0});const l=document.getElementById("va-canvas");if(!l||e||t)l&&(l.style.display="none");else{const x=l.getContext("2d"),b=.5;let E=0,q=0;function d(){E=l.width=window.innerWidth*b,q=l.height=window.innerHeight*b,l.style.width=window.innerWidth+"px",l.style.height=window.innerHeight+"px"}d(),window.addEventListener("resize",d);const L=[{x:.3*E,y:.3*q,r:280,vx:.6,vy:.4,c:"96,165,250",phase:0},{x:.7*E,y:.4*q,r:340,vx:-.5,vy:.7,c:"167,139,250",phase:2},{x:.5*E,y:.7*q,r:300,vx:.4,vy:-.5,c:"139,92,246",phase:4},{x:.2*E,y:.8*q,r:260,vx:.7,vy:-.3,c:"59,130,246",phase:1}].map(e=>({...e,r:e.r*b,vx:e.vx*b,vy:e.vy*b}));let S=E/2,A=q/2,C=0,$=null,M=!0,F=!0;function u(){S+=.06*(r.x*b-S),A+=.06*(r.y*b-A),x.clearRect(0,0,E,q),x.globalCompositeOperation="lighter";for(let e=0;e<L.length;e++){const t=L[e];t.x+=t.vx+.3*Math.sin(.5*C+t.phase)*b,t.y+=t.vy+.3*Math.cos(.4*C+t.phase)*b,t.x+=.002*(S-t.x),t.y+=.002*(A-t.y),t.x<-t.r?t.x=E+t.r:t.x>E+t.r&&(t.x=-t.r),t.y<-t.r?t.y=q+t.r:t.y>q+t.r&&(t.y=-t.r);const n=t.r+40*Math.sin(C+t.phase)*b,o=x.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)`),x.fillStyle=o,x.beginPath(),x.arc(t.x,t.y,n,0,2*Math.PI),x.fill()}x.globalCompositeOperation="source-over",C+=.01,$=requestAnimationFrame(u)}function m(){!$&&M&&F&&($=requestAnimationFrame(u))}function h(){$&&(cancelAnimationFrame($),$=null)}m(),document.addEventListener("visibilitychange",()=>{F=!document.hidden,F?m():h()}),window.addEventListener("scroll",()=>{const e=window.scrollY<window.innerHeight;e!==M&&(M=e,e?m():h())},{passive:!0})}function v(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",v(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("[data-magnetic]").forEach(e=>{e.addEventListener("mousemove",v(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 p=document.querySelector(".va-nav"),y=document.querySelector(".va-menu-btn");if(p&&y){const I=e=>{p.classList.toggle("open",e),y.setAttribute("aria-expanded",String(e)),y.setAttribute("aria-label",e?"Cerrar menú":"Abrir menú")};y.addEventListener("click",()=>I(!p.classList.contains("open"))),p.querySelectorAll(".va-nav-links a").forEach(e=>e.addEventListener("click",()=>I(!1))),document.addEventListener("keydown",e=>{"Escape"===e.key&&I(!1)})}const f=document.querySelectorAll("[data-section]"),g=document.querySelectorAll(".va-dot");if(g.forEach(e=>e.addEventListener("click",()=>{const t=document.querySelector(`[data-section="${e.dataset.target}"]`);t&&window.scrollTo({top:t.offsetTop-80,behavior:"smooth"})})),f.length&&"IntersectionObserver"in window){const k=new IntersectionObserver(e=>{e.forEach(e=>{if(e.isIntersecting){const t=e.target.dataset.section;g.forEach(e=>e.classList.toggle("active",e.dataset.target===t))}})},{rootMargin:"-40% 0px -50% 0px"});f.forEach(e=>k.observe(e))}function w(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(()=>w(e),200);else if("IntersectionObserver"in window){const t=new IntersectionObserver(n=>{n[0].isIntersecting&&(w(e),t.disconnect())},{threshold:.1});t.observe(e)}setTimeout(()=>w(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"}))})}();