Skip to content

Instantly share code, notes, and snippets.

@ttntm
Created March 20, 2020 11:21
Show Gist options
  • Save ttntm/e2f6e68c254caa9f2ef562fcbabc5c1b to your computer and use it in GitHub Desktop.
Save ttntm/e2f6e68c254caa9f2ef562fcbabc5c1b to your computer and use it in GitHub Desktop.
Vanilla JS scroll to top
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