diff --git a/frontend/components/home/ProductsShowcase.vue b/frontend/components/home/ProductsShowcase.vue index 788d81e..6e8621a 100644 --- a/frontend/components/home/ProductsShowcase.vue +++ b/frontend/components/home/ProductsShowcase.vue @@ -2,135 +2,208 @@ // import import useHomeData from "~/composables/api/home/useHomeData"; +import { motion } from "motion-v"; // state const { data: homeData } = useHomeData(); -const { $gsap: gsap, $ScrollTrigger: ScrollTrigger } = useNuxtApp(); +const activeSlide = ref(0); -let gsapTimeline: gsap.core.Timeline; -let scrollTrigger: ScrollTrigger; +const variants = { + hide: { opacity: 0, y: -200 }, + show: { + opacity: 1, + y: 0, + transition: { + when: "beforeChildren", + staggerChildren: 0.15, + }, + }, + exit: (slidesCount: number) => { + return { + opacity: 0, + y: 200, + transition: { + when: "afterChildren", + delay: slidesCount * 0.21, + staggerChildren: 0.1, + staggerDirection: 1, + }, + }; + }, +}; -// lifecycle +const childContentVariants = { + hide: { + filter: "blur(20px)", + opacity: 0, + }, + show: { + filter: "blur(0px)", + opacity: 1, + }, + exit: { + filter: "blur(20px)", + opacity: 0, + }, +}; + +const childImageVariants = { + hide: { + filter: "blur(20px)", + y: 70, + scale: 0.65, + opacity: 0, + }, + show: { + filter: "blur(0px)", + y: 0, + scale: 1, + opacity: 1, + transition: { + type: "spring", + damping: 20, + }, + }, + exit: { + filter: "blur(20px)", + y: 70, + scale: 0.65, + opacity: 0, + transition: { + default: { + type: "spring", + damping: 20, + }, + opacity: { + duration: 0.1, + }, + }, + }, +}; + +const nextSlide = () => { + const slidesCount = homeData.value!.show_case_slider.length; + if (activeSlide.value > slidesCount - 2) { + activeSlide.value = 0; + } else { + activeSlide.value = activeSlide.value + 1; + } +}; onMounted(() => { - gsapTimeline = gsap.timeline(); - const showcaseElements = gsap.utils.toArray(".showcase-slide"); + nextSlide(); - setTimeout(() => { - showcaseElements.forEach((element, index) => { - gsapTimeline.fromTo( - element, - index === 0 - ? { - opacity: 1, - scale: 1, - // rotateX: -25, - zIndex: 1, - top: 0, - ease: "none", - } - : { - opacity: 0, - scale: 1, - // rotateX: -25, - zIndex: 1, - top: 20, - ease: "none", - }, - { - opacity: 1, - scale: 1, - // rotateX: 0, - zIndex: 5, - top: 0, - ease: "none", - }, - index === 0 ? "-=0%" : undefined - ); - - if (index < showcaseElements.length - 1) { - gsapTimeline.to(element, { - opacity: 0, - scale: 1.03, - // rotateX: 25, - top: -20, - ease: "none", - }); - } - }); - - scrollTrigger = ScrollTrigger.create({ - trigger: "#products-showcase-container", - animation: gsapTimeline, - scrub: 1, - pin: true, - start: "top top", - anticipatePin: 1, - // markers: true, - end: "bottom top", - }); - - setTimeout(() => { - scrollTrigger.update(); - scrollTrigger.refresh(); - }, 1000); - }, 1000); -}); - -onUnmounted(() => { - gsapTimeline.progress(1).pause(); - gsapTimeline.kill(); + setInterval(() => { + nextSlide(); + }, 5000); });