Created
March 2, 2020 14:24
-
-
Save DZuz14/60b0feb441de7581230aee93054994b7 to your computer and use it in GitHub Desktop.
Smooth Transition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const smoothTransition = () => { | |
let _slides = [] | |
// We're at the last slide. | |
if (activeSlide === slides.length - 1) | |
_slides = [slides[slides.length - 2], lastSlide, firstSlide] | |
// We're back at the first slide. Just reset to how it was on initial render | |
else if (activeSlide === 0) _slides = [lastSlide, firstSlide, secondSlide] | |
// Create an array of the previous last slide, and the next two slides that follow it. | |
else _slides = slides.slice(activeSlide - 1, activeSlide + 2) | |
setState({ | |
...state, | |
_slides, | |
transition: 0, | |
translate: getWidth() | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment