API

API

The browser module exports createCarousel. The React package adds useCarousel and a Carousel component.

NameDescription
createCarousel(viewport, options?)Binds a scroll-snap strip. Options: slides, align, loop, drag, group, autoplay, releaseMotion, releaseDuration, onChange.
releaseMotionHow a released mouse drag travels to its slide. "spring" starts at the drag speed and eases in; "native" uses the browser's smooth scroll. Both pick the same slide. "spring" by default; reduced motion jumps.
releaseDurationHow long the spring glide takes, in milliseconds. 260 by default.
next(), prev(), goTo(index, behavior?)Moves by one group or to a slide. goTo takes an optional scroll behavior.
getState(), subscribe(listener)Index, count, progress, canPrev, canNext, and whether it is playing, dragging or looping.
play(), pause()Starts and stops autoplay. It also waits for hover, focus, drag and hidden tabs on its own.
setEnabled(enabled)Turns scrolling and dragging off and back on, keeping the current position.
refresh()Measures again after slides are added or removed.
destroy()Removes listeners and restores the viewport.
syncCarousels(...carousels)Keeps several carousels on the same index. Returns a function that stops it.