Nathanwoodburn.github.io/assets/js/app.min.js

1 line
1.4 KiB
JavaScript

const parallax_el=document.querySelectorAll(".parallax"),main=document.querySelector(".main");let xValue=0,yValue=0,rotateDegree=0;function update(e){parallax_el.forEach((t=>{let a=t.dataset.speedx,i=t.dataset.speedy,n=t.dataset.speedz,r=t.dataset.rotation,l=parseFloat(getComputedStyle(t).left)<window.innerWidth/2?1:-1,o=(e-parseFloat(getComputedStyle(t).left))*l*.1;t.style.transform=`perspective(2300px) translateZ(${o*n}px) rotateY(${rotateDegree*r}deg) translateX(calc(-50% + ${-xValue*a}px)) translateY(calc(-50% + ${yValue*i}px))`}))}update(0),window.addEventListener("mousemove",(e=>{timeline.isActive()||(xValue=e.clientX-window.innerWidth/2,yValue=e.clientY-window.innerHeight/2,rotateDegree=xValue/(window.innerWidth/2)*20,update(e.clientX))})),window.innerWidth>=725?main.style.maxHeight=.6*window.innerWidth+"px":main.style.maxHeight=1.6*window.innerWidth+"px";let timeline=gsap.timeline();setTimeout((()=>{parallax_el.forEach((e=>{e.style.transition="0.45s cubic-bezier(0.2, 0.49, 0.32, 0.99)"}))}),1e3*timeline.endTime()),Array.from(parallax_el).filter((e=>!e.classList.contains("text"))).forEach((e=>{timeline.from(e,{top:e.offsetHeight/2+ +e.dataset.distance+"px",duration:3.5,ease:"power3.out"},"1")})),timeline.from(".text .para2",{y:window.innerHeight-document.querySelector(".text .para1").getBoundingClientRect().top+200,duration:2},"2.5").from(".text .para1",{y:-150,opacity:0,duration:1.5},"3").from(".hide",{opacity:0,duration:1.5},"3");