Created
September 21, 2021 20:15
-
-
Save danielcranney/a04155f899b753b39a8d59bbe2ac7d04 to your computer and use it in GitHub Desktop.
Left/Right ScrollTo with Smooth Scroll
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 handleSlideRight = () => { | |
document.getElementById("colorContent").scrollTo({ | |
top: 0, | |
left: Math.max( | |
(scrollAmount += 5), | |
document.getElementById("colorContent").clientWidth | |
), | |
behavior: "smooth", | |
}); | |
}; | |
const handleSlideLeft = () => { | |
document.getElementById("colorContent").scrollTo({ | |
top: 0, | |
left: Math.min((scrollAmount -= 5), scrollMin), | |
behavior: "smooth", | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment