react-snap-carousel icon indicating copy to clipboard operation
react-snap-carousel copied to clipboard

how to realize autoplay? is it possible?

Open Barklim opened this issue 1 year ago • 1 comments

Barklim avatar Aug 24 '23 15:08 Barklim

I think it's a bad idea as it takes control away from the user, but you could implement it relatively easily, something like this:

useEffect(() => {
    const timeout = setTimeout(() => {
      if (activePageIndex === pages.length - 1) {
        goTo(0)
      } else {
        goTo(activePageIndex + 1)
      }
    }, 2500);
    return () => clearTimeout(timeout);
  }, [activePageIndex, pages]);

You might want to disable it when a user's mouse is hovered over it, or perhaps when a user is scrolling.

https://codesandbox.io/s/react-snap-carousel-autoplay-j38xzj?file=/src/Carousel.tsx:1342-1607

richardscarrott avatar Aug 24 '23 16:08 richardscarrott

Closing as can be implemented by user as per above.

richardscarrott avatar May 16 '24 08:05 richardscarrott