Created
January 7, 2019 11:41
-
-
Save ivan-marquez/619bb85ebf5bfc516801812c736f0528 to your computer and use it in GitHub Desktop.
Detect when scroll reaches bottom of window.
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
export function scrolledToBottom(window, marginFromBottom = 0) { | |
const documentBody = window.document.body; | |
const documentElement = window.document.documentElement; | |
const scrollTop = | |
(documentElement && documentElement.scrollTop) || documentBody.scrollTop; | |
const scrollHeight = | |
(documentElement && documentElement.scrollHeight) || | |
documentBody.scrollHeight; | |
const clientHeight = documentElement.clientHeight || window.innerHeight; | |
const bottomReached = | |
Math.ceil(scrollTop + clientHeight + marginFromBottom) >= scrollHeight; | |
return bottomReached; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment