0 points

js-scrollToTop


dashboard

Sun Oct 18 2020 17:00:10 GMT+0000 (UTC)

Posted by @aymanelya

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_copy Copy

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