Skip to content

Instantly share code, notes, and snippets.

@YasinKuralay
Last active June 2, 2021 07:29
Show Gist options
  • Save YasinKuralay/3282ac9458746d78ad86d80b82071fdf to your computer and use it in GitHub Desktop.
Save YasinKuralay/3282ac9458746d78ad86d80b82071fdf to your computer and use it in GitHub Desktop.
JS Document height
// Calculation on load because otherwise IOS devices return an unreliable height variable ( different values at different places )
window.addEventListener("load", () => {
// See stackoverflow post https://stackoverflow.com/a/1147768
let height = Math.max(
document.body.scrollHeight,
document.body.offsetHeight,
html.clientHeight,
html.scrollHeight,
html.offsetHeight
);
});
// If scroll direction is upwards, and we are not at the bottom 15px
if (
window.pageYOffset < lastKnownScrollPosition &&
window.innerHeight + window.pageYOffset <= height - 15
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment