Skip to main content

<Carousel/>

Carousel is a wrapper for the whole slider. You MUST use this component as a wrapper so other slider components can share some common props.

Import

import {Carousel} from "react-scroll-snap-anime-slider";

Usage

<Carousel
totalSlides={10}
visibleSlides={3}
step={1}
>
// any elements
</Carousel>

Props

NameTypeRequiredDefaultDescription
DIV PropsReact.HTMLAttributes<HTMLDivElement>NoDIV Element props
totalSlidesnumberYesTotal slides in this slider
slideWidthnumberNo0
auto height
Use to calculate slide's height in dimension, such as width:height = 16:9
slideHeightnumberNo0
auto height
Use to calculate slide's height in dimension, such as width:height = 16:9
visibleSlidesnumberNo1How many visible slides (N), slide width = 100% / N
stepnumberNo1How mange slides per step (when click previous and next button)
currentSlidenumberNo0Current slide index (from 0)
slideMarginstringNoMargin between each slide
value can be any pixel value: "5px", "1rem", ...
The result will be double, such as "5px" => then the gap between 2 slides will be "10px"
trayPaddingstringNoPadding the slider track to offset left/right side to see a little bit of prev/next hidden slide
freeScrollbooleanNofalseIs freely scrolling (not using snapping)?
onSlidefuncNo(props: OnSlideProps) => void
A callback function when slider is sliding
snapAnimationstring, [number,number,number,number]NoeaseOutUse simple ease function or Cubic Bezier parameters for snapping animation
(Used for snapping after mouse scrolling, and next/back button anime sliding)
inertiaPowernumberNo0.4How light is the slide?
Higher number -> slide further
(Only for mouse scrolling)
inertiaStopSpeednumberNo800The speed to reach (speed is decreasing), to stop inertia animation
(Only for mouse scrolling)

Other Props

OnSlideProps

This is an object with some helpful slider latest state variables inside.

NameTypeDescription
scrollLeftnumberHow far has scrolled in px
currentSlidenumberCurrent slide index (from 0 ~ (length - visible slide - 1))
slideWidthnumberWidth in px of a slide
trayWidthnumberwidth in px of the tray DIV

An example such as you can update your local current slide index to match the slide index of the slider:

<Carousel
onSlide={({ currentSlide }) => { localCurrentSlide.index = currentSlide; }}
></Carousel>

CSS

You can override the default style by using these class names.

Rule Name
.rssas-wrapper