F
F
fillpower2020-09-19 19:34:02
JavaScript
fillpower, 2020-09-19 19:34:02

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

1 answer(s)
0
0xD34F, 2020-09-19
@fillpower

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 question

Ask a Question

731 491 924 answers to any question