Skip to content

Instantly share code, notes, and snippets.

@saltlakeryan
Created November 15, 2018 21:49
Show Gist options
  • Save saltlakeryan/d789191e9f8f6b7b50ff53ba6894b420 to your computer and use it in GitHub Desktop.
Save saltlakeryan/d789191e9f8f6b7b50ff53ba6894b420 to your computer and use it in GitHub Desktop.
var Scroller = (function() {
var scrollHandle = 0;
var height = () => {
var body = document.body, html = document.documentElement;
var height = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight,html.offsetHeight );
return height;
};
var slowScroll = (amt) => {
window.scrollBy({left: 0, top: amt, behavior: 'smooth'});
};
var scrollBottom = (defaultAmount, defaultPeriod) => {
var amt = defaultAmount || 250;
var period = defaultPeriod || 80;
var lengths = height() / amt;
scrollHandle = window.setInterval(() => {slowScroll(amt)}, period);
window.setTimeout(() => {window.clearInterval(scrollHandle);}, period * lengths);
};
var stopScroll = () => {
window.clearInterval(scrollHandle);
};
return {height, slowScroll, scrollBottom, stopScroll};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment