YIZHUANG / react-multi-carousel

A lightweight production-ready Carousel that rocks supports multiple items and server-side rendering with no dependency. Bundle size 2kb.
MIT License
1.28k stars 289 forks source link

How can I start the carousel at a specific item on startup, instead of the first one? #362

Open nbnkhanh opened 2 years ago

nbnkhanh commented 2 years ago

![Uploading image.png…]() I want the default slide of the carousel on start-up to be at slide 2, for example, instead of slide 0 by default. In other words, when the user first opens the webpage, the carousel is already somewhere in the middle, not on the leftmost. What should I do to obtain this?

NipunaC95 commented 1 year ago

you can use this workaround

const [timer, setTimer] = useState(false)

useEffect(() => { setTimeout(() => { setTimer(true) }, 1000) }, [])

return ( <Carousel additionalTransfrom={0} arrows={true} autoPlay={timer ? true: false}

muktank commented 10 months ago

You can use goToSlide function.

` let carouselRef;

const responsive = {
    desktop: {
        breakpoint: { max: 3000, min: 100 },
        items: itemsPerSlide,
        slidesToSlide: itemsPerSlide
    }
};

useEffect(() => {
    carouselRef?.goToSlide(<slide_number>);
}, []);

return (
    <div>
        <Carousel
            ref={(e) => carouselRef = e}
            responsive={responsive}
            containerClass="multiCarousel"
            customRightArrow={<CustomRightArrow />}
            customLeftArrow={<CustomLeftArrow />}
            renderButtonGroupOutside={true}
        >
            {children}
        </Carousel>
    </div>
);

`