Scroll to the top of the page

PHOTO EMBED

Sun Oct 18 2020 17:00:10 GMT+0000 (Coordinated Universal Time)

Saved by @aymanelya #javascript

const scrollToTop = () => {
  const c = document.documentElement.scrollTop || document.body.scrollTop;
  if (c > 0) {
    window.requestAnimationFrame(scrollToTop);
    window.scrollTo(0, c - c / 8);
  }
};

// Example
scrollToTop();
content_copyCOPY

https://blog.madza.dev/24-modern-es6-code-snippets-to-solve-practical-js-problems?guid