Last active
January 21, 2021 07:32
-
-
Save EastSun5566/334be45a4d26edc5a2e3bc3ddaacfd22 to your computer and use it in GitHub Desktop.
Simple smooth scroll with pure JavaScript
This file contains hidden or 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
// To element | |
const scrollTo = (selectors) => { | |
document | |
.querySelector(selectors) | |
.scrollIntoView({ behavior: 'smooth' }); | |
}; | |
// To top | |
const scrollToTop = () => { | |
window.scroll({ | |
top: 0, | |
behavior: 'smooth', | |
}); | |
}; | |
// To bottom | |
const scrollToBottom = () => { | |
window.scroll({ | |
top: document.documentElement.clientHeight, | |
behavior: 'smooth', | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment