Last active
December 10, 2018 17:00
-
-
Save codeepic/3c973779f7b18648cd421d43ecab5c56 to your computer and use it in GitHub Desktop.
Scroll to top (smooth)
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
// https://stackoverflow.com/questions/15935318/smooth-scroll-to-top | |
// based on Gor answer | |
const scrollToTop = () => { | |
const c = document.documentElement.scrollTop || document.body.scrollTop; | |
if (c > 0) { | |
window.requestAnimationFrame(scrollToTop); | |
window.scrollTo(0, c - c / 8); | |
} | |
}; | |
scrollToTop(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment