Skip to content

Instantly share code, notes, and snippets.

@sr9yar
Created February 20, 2021 12:17
Show Gist options
  • Save sr9yar/46d07785eac774682c681acf1eeb1a47 to your computer and use it in GitHub Desktop.
Save sr9yar/46d07785eac774682c681acf1eeb1a47 to your computer and use it in GitHub Desktop.
Scroll to top animation with js
goToTop() {
const scrollToTop = window.setInterval(() => {
const pos = window.pageYOffset;
if (pos > 0) {
window.scrollTo(0, pos - 20);
} else {
window.clearInterval(scrollToTop);
}
}, 4);
this.router.navigate(['/']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment