From d47c023728c06ab8e0bfdd3cefd66a01f405ec45 Mon Sep 17 00:00:00 2001 From: J Shiva Shankar <144578658+STXRSHIVA@users.noreply.github.com> Date: Sun, 20 Oct 2024 16:30:09 +0530 Subject: [PATCH] improved carousal --- frontend/src/components/ui/ReviewCarousel.jsx | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/ui/ReviewCarousel.jsx b/frontend/src/components/ui/ReviewCarousel.jsx index b7f0699b..c2e14b44 100644 --- a/frontend/src/components/ui/ReviewCarousel.jsx +++ b/frontend/src/components/ui/ReviewCarousel.jsx @@ -71,15 +71,16 @@ const ReviewCarousel = () => { const nextSlide = () => { setCurrentIndex((prevIndex) => - prevIndex === reviews.length - 4 ? 0 : prevIndex + 1 + prevIndex === reviews.length - 6 ? 0 : prevIndex + 1 ); }; const prevSlide = () => { setCurrentIndex((prevIndex) => - prevIndex === 0 ? reviews.length - 4 : prevIndex - 1 + prevIndex === 0 ? reviews.length - 6 : prevIndex - 1 ); }; + const [cardsToShow, setCardsToShow] = useState(1); const updateCardsToShow = () => { @@ -94,7 +95,10 @@ const ReviewCarousel = () => { updateCardsToShow(); window.addEventListener('resize', updateCardsToShow); + const intervalId = setInterval(nextSlide, 3000); // Change slide every 3 seconds + return () => { + clearInterval(intervalId); // Cleanup interval on unmount window.removeEventListener('resize', updateCardsToShow); }; }, []); @@ -107,8 +111,8 @@ const ReviewCarousel = () => { -
-
+
+
{ >
- {/* */} { <>