Skip to content

Instantly share code, notes, and snippets.

@EastSun5566
Last active January 21, 2021 07:32
Show Gist options
  • Save EastSun5566/334be45a4d26edc5a2e3bc3ddaacfd22 to your computer and use it in GitHub Desktop.
Save EastSun5566/334be45a4d26edc5a2e3bc3ddaacfd22 to your computer and use it in GitHub Desktop.
Simple smooth scroll with pure JavaScript
// 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