How to prevent a carousel from slipping when it reaches the last item?

Asked

Viewed 23 times

0

I’m making a carousel from scratch, it contains 7 items, the problem is when it gets to the last item I can still click to the next one, I want every time I get to the last item the carousel stop.

I’m using Transform to make the effect of passing items, so every time I press the next button, translateX increases, I don’t know if this is the best approach.

 transform: ${({ currentSlide }) =>
        currentSlide ? `translateX(-${currentSlide}00%)` : "translate(0%)"};

I don’t want all this space when I get to the last item

enter image description here

This should be the expected result

enter image description here

Code: https://codesandbox.io/s/dogs-carousel-u7126?file=/src/App.tsx

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.