Created
January 24, 2019 05:10
-
-
Save lovetingyuan/de9aa69ae8a62b2827f620e7f401fc12 to your computer and use it in GitHub Desktop.
scroll window or element
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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