Created
November 15, 2018 21:49
-
-
Save saltlakeryan/d789191e9f8f6b7b50ff53ba6894b420 to your computer and use it in GitHub Desktop.
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
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