Created
March 20, 2020 11:21
-
-
Save ttntm/e2f6e68c254caa9f2ef562fcbabc5c1b to your computer and use it in GitHub Desktop.
Vanilla JS scroll to top
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
scrollTo = (el) => { | |
window.scroll({ | |
behavior: 'smooth', | |
left: 0, | |
top: el.offsetTop | |
}); | |
} | |
document.getElementById("btt").addEventListener('click', () => { | |
scrollTo(document.getElementById("top")); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment