Last active
November 11, 2020 14:34
-
-
Save HamedFathi/6648911d06ad12ba0d44867837a123a8 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
function scrollUp(start?: Function, end?: Function) { | |
const el = (document.documentElement || document.body); | |
if (start) start(); | |
el.scroll({ | |
top: 0, | |
left: 0, | |
behavior: 'smooth' | |
}); | |
if (end) end(); | |
} | |
function scrollBottom(start?: Function, end?: Function) { | |
const scrollingElement = (document.scrollingElement || document.body); | |
const el = (document.documentElement || document.body); | |
if (start) start(); | |
const smoothScroll = (h: number) => { | |
let i = h || 0; | |
if (i < scrollingElement.scrollHeight) { | |
setTimeout(() => { | |
el.scrollTo(0, i); | |
smoothScroll(i + 10); | |
}, 5); | |
if (end) end(); | |
} | |
} | |
smoothScroll(0); | |
} | |
function scrollBottomFast(start?: Function, end?: Function) { | |
const scrollingElement = (document.scrollingElement || document.body); | |
const el = (document.documentElement || document.body); | |
if (start) start(); | |
el.scrollTo(0, scrollingElement.scrollHeight); | |
if (end) end(); | |
} | |
export { scrollUp, scrollBottom, scrollBottomFast } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment