Created
August 17, 2020 21:01
-
-
Save simicd/1146027297901e568b262afd99f224ff to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Paste into Browser for smooth scrolling from top to bottom | |
* @see https://css-tricks.com/smooth-scrolling-for-screencasts/ | |
*/ | |
const scrollElement = (element, scrollPosition, duration) => { | |
// useful while testing to re-run it a bunch. | |
// element.removeAttribute("style"); | |
const style = element.style; | |
style.transition = duration + 's'; | |
style.transitionTimingFunction = 'ease-in-out'; | |
style.transform = 'translate3d(0, ' + -scrollPosition + 'px, 0)'; | |
} | |
scrollElement( | |
document.body, | |
( | |
document.body.getBoundingClientRect().height | |
- | |
document.documentElement.clientHeight | |
+ | |
25 // Stopping point | |
), | |
5 // seconds | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment