Skip to content

Instantly share code, notes, and snippets.

@lovetingyuan
Created January 24, 2019 05:10
Show Gist options
  • Save lovetingyuan/de9aa69ae8a62b2827f620e7f401fc12 to your computer and use it in GitHub Desktop.
Save lovetingyuan/de9aa69ae8a62b2827f620e7f401fc12 to your computer and use it in GitHub Desktop.
scroll window or element
const scrollToTop = () => {
const c = document.documentElement.scrollTop || document.body.scrollTop;
if (c > 0) {
window.requestAnimationFrame(scrollToTop);
window.scrollTo(0, c - c / 8);
}
};
const smoothScroll = element =>
document.querySelector(element).scrollIntoView({
behavior: 'smooth'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment