diff --git a/src/components/sections/HeroSection.vue b/src/components/sections/HeroSection.vue index e6f6d2f..5f7506c 100644 --- a/src/components/sections/HeroSection.vue +++ b/src/components/sections/HeroSection.vue @@ -7,37 +7,63 @@ gsap.registerPlugin(ScrollTrigger) - const main = ref(null); let tl; let ctx; + +function setBoxes() { + + const wrapper = main.value.querySelector('.content-wrapper'); + const rect = wrapper.getBoundingClientRect(); + + const boxes = gsap.utils.toArray(".box"); + + gsap.set(".title", { y: 200 }); + + boxes.forEach((box) => { + + const randomX = gsap.utils.random(0, rect.width); + const randomY = gsap.utils.random(0, rect.height); + + gsap.set(box, { + x: randomX, + y: randomY, + xPercent: -50, + yPercent: -50 + }); + + }); +} + + + + function toggleTimeline() { tl.reversed(!tl.reversed()) } function startNextAnimation() { + const centerX = window.innerWidth / 2 + const centerY = window.innerHeight / 2 + const radius = 250 ctx = gsap.context(() => { - const boxes = gsap.utils.toArray(".box") - tl = gsap.timeline({ scrollTrigger: { trigger: ".scroll-trigger-ready__worm-wrap", start: "top 00%", - end: "bottom 30%", - scrub: 1 + end: "bottom 35%", + scrub: 2 } }) - tl - .to(boxes[0], { x: gsap.utils.random(300, 600), rotate: 180 }) - .to(boxes[1], { x: -gsap.utils.random(300, 500), rotate: -180 }, "<") - .to(boxes[2], { x: gsap.utils.random(300, 400), rotate: 180 }) - .to(boxes[3], { x: gsap.utils.random(300, 500), rotate: 180 }) - .to(boxes[4], { x: -gsap.utils.random(300, 400), rotate: -180 }, "<") - .to(boxes[5], { x: gsap.utils.random(300, 500), rotate: 180 }) - .to(boxes[6], { x: -gsap.utils.random(300, 600), rotate: 180 }) - .to(".title", { + tl.to(boxes, { + y: () => gsap.utils.random(-400, -150), + + rotate: () => gsap.utils.random(-180, 180), + ease: "none", + stagger: 0.05 + }).to(".title", { y: window.innerHeight - 130, duration: 4.0, ease: "power2.inOut" @@ -47,6 +73,7 @@ function startNextAnimation() { } onMounted(() => { + setBoxes(); startNextAnimation(); }); @@ -57,22 +84,36 @@ onUnmounted(() => {