Answer the question
In order to leave comments, you need to log in
How to switch slide by step in carousel?
Good afternoon, I implemented a dynamic display of the number of cards in the carousel. Now I would like to scroll by a certain step, for example 2, it is not clear how to do this. Right now my cards are switching by 1.
Here is what I did:
https://codesandbox.io/s/crazy-leakey-iucrt
Answer the question
In order to leave comments, you need to log in
nextSlide = ({ target: { dataset: { step } } }) => {
this.setState(({ images: { length }, currentImageIndex: i }) => ({
currentImageIndex: Math.max(0, Math.min(length - this.props.slidesToShow, i + +step)),
}));
};
<button onClick={this.nextSlide} data-step="-1">PREV</button>
<button onClick={this.nextSlide} data-step="+2">NEXT</button>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question