Skip to content

Instantly share code, notes, and snippets.

@alordiel
Last active April 10, 2019 15:12
Show Gist options
  • Save alordiel/10bb4bee0fceb81f74191b7c93d402d7 to your computer and use it in GitHub Desktop.
Save alordiel/10bb4bee0fceb81f74191b7c93d402d7 to your computer and use it in GitHub Desktop.
Smooth pure js scroll to ID
scrollTo (id) {
window.scrollTo({
top: document.getElementById(id).offsetTop,
left: 0,
behavior: 'smooth'
});
}
// Doesn't work in IE
//https://developer.mozilla.org/en-US/docs/Web/API/Window/scroll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment