From 726ab2afdcf8390ae17c999b2983b1a07c41af7f Mon Sep 17 00:00:00 2001 From: Bhoopesh Date: Tue, 5 Dec 2023 21:08:29 +0530 Subject: [PATCH] feat: animations for clusters carousel --- .../ClusterCarousel/ClusterCarousel.tsx | 51 +++++++++++++++++-- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/src/components/ClusterCarousel/ClusterCarousel.tsx b/src/components/ClusterCarousel/ClusterCarousel.tsx index 2649f9d..6b1fa92 100644 --- a/src/components/ClusterCarousel/ClusterCarousel.tsx +++ b/src/components/ClusterCarousel/ClusterCarousel.tsx @@ -14,6 +14,7 @@ import temp from '../../assets/images/temp.png'; import leftArrow from '../../assets/images/leftArrow.png'; import rightArrow from '../../assets/images/rightArrow.png'; +import { useState } from 'react'; const ClusterCarousel = () => { const slides = [1, 2, 3, 4, 5, 6, 7, 8, 9]; @@ -36,10 +37,45 @@ const ClusterCarousel = () => { }, }; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const [swiper, setSwiper] = useState(null); + + const handleSlideChange = (index: number) => { + const currentSlide = swiper?.slides[index]; + if (currentSlide) { + currentSlide.style.transform = 'scale(1.1)'; + currentSlide.style.opacity = '1'; + currentSlide.style.transition = 'transform 0.5s ease-in-out'; + } + + const previousSlide = swiper?.slides[index - 1]; + if (previousSlide) { + previousSlide.style.transform = 'scale(0.67)'; + previousSlide.style.opacity = '0.4'; + previousSlide.style.transition = 'transform 0.5s ease-in-out'; + } + + const nextSlide = swiper?.slides[index + 1]; + if (nextSlide) { + nextSlide.style.transform = 'scale(0.67)'; + nextSlide.style.opacity = '0.4'; + nextSlide.style.transition = 'transform 0.5s ease-in-out'; + } + }; + + const goToNextSlide = () => { + swiper?.slideNext(); + }; + + const goToPreviousSlide = () => { + swiper?.slidePrev(); + }; + return (
< { pagination={{ enabled: false }} breakpoints={breakpoints} className="w-full lg:w-[66%] xl:w-3/4 h-full flex items-center justify-center z-10" + onSlideChange={swiper => handleSlideChange(swiper?.activeIndex)} > {slides.map(slide => (
{ width={450} objectPosition="center" objectFit="contain" - className={'max-sm:rounded-xl'} + className={'rounded-lg'} alt="cluster" />
@@ -72,13 +109,19 @@ const ClusterCarousel = () => {
<
-
+
<
BATMAN
-
+
>