From 33d9ae2615814c38065e9ca9cd2dcc85001aeb09 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 27 Aug 2021 15:57:24 +0700 Subject: [PATCH] :bug: bug: carousel :%s --- pages/test.tsx | 8 +++----- .../common/CarouselCommon/CarouselCommon.tsx | 11 ++++++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pages/test.tsx b/pages/test.tsx index f6d4011eb..619bd0110 100644 --- a/pages/test.tsx +++ b/pages/test.tsx @@ -1,5 +1,5 @@ import { useState } from 'react' -import { ButtonCommon, Layout, ModalCommon } from 'src/components/common' +import { ButtonCommon, Layout, ModalCommon, ProductCarousel } from 'src/components/common' import { CollectionCarcousel } from 'src/components/modules/home' import image5 from '../public/assets/images/image5.png' import image6 from '../public/assets/images/image6.png' @@ -107,12 +107,10 @@ export default function Test() { Lorem ipsum dolor sit amet consectetur adipisicing elit. Consectetur officiis dolorum ea incidunt. Sint, cum ullam. Labore vero quod itaque, officia magni molestias! Architecto deserunt soluta laborum commodi nesciunt delectus similique temporibus distinctio? Facere eaque minima enim modi magni, laudantium, animi mollitia beatae repudiandae maxime labore error nesciunt, nisi est? - ) diff --git a/src/components/common/CarouselCommon/CarouselCommon.tsx b/src/components/common/CarouselCommon/CarouselCommon.tsx index a9011a074..796e46eaf 100644 --- a/src/components/common/CarouselCommon/CarouselCommon.tsx +++ b/src/components/common/CarouselCommon/CarouselCommon.tsx @@ -35,14 +35,18 @@ const CarouselCommon = ({ slidesPerView, slideChanged(s) { setCurrentSlide(s.details().relativeSlide) + + }, + afterChange(s) { let dot = 0 dotArr.forEach((index)=>{ - if(s.details().relativeSlide >= Math.floor(index)){ + if(s.details().relativeSlide >= index){ dot = index } }) + console.log(dot) setDotActive(dot) - }, + } }) useEffect(() => { @@ -65,7 +69,8 @@ const CarouselCommon = ({ } const onDotClick = (index:number) => { - slider.moveToSlideRelative(Math.floor(index)) + slider.moveToSlideRelative(index) + setDotActive(index) } return (