Created
September 26, 2019 13:34
-
-
Save juanlatorre/bbb19fd397eb1f84d2cb57bd4c49227f to your computer and use it in GitHub Desktop.
No If slider (thanks math) written in JavaScript -> https://dev.to/ranewallin/this-simple-math-hack-lets-you-create-an-image-carousel-without-any-if-statements-5chj
This file contains 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 imageData = [ 'image1.png', 'img2.png', 'img3.png' ]; | |
const currentImage = 0; | |
const handleImageChange = (direction) => { | |
if (direction == 'forward') | |
currentImage = (currentImage + 1) % imageData.length; | |
else | |
currentImage = (currentImage - 1 + imageData.length) % imageData.length; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment