Skip to content

Instantly share code, notes, and snippets.

@DZuz14
Created March 2, 2020 14:24
Show Gist options
  • Save DZuz14/60b0feb441de7581230aee93054994b7 to your computer and use it in GitHub Desktop.
Save DZuz14/60b0feb441de7581230aee93054994b7 to your computer and use it in GitHub Desktop.
Smooth Transition
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