Skip to content

Instantly share code, notes, and snippets.

@simicd
Created August 17, 2020 21:01
Show Gist options
  • Save simicd/1146027297901e568b262afd99f224ff to your computer and use it in GitHub Desktop.
Save simicd/1146027297901e568b262afd99f224ff to your computer and use it in GitHub Desktop.
/**
* 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