Skip to content

Instantly share code, notes, and snippets.

@akccakcctw
Last active September 17, 2018 04:16
Show Gist options
  • Save akccakcctw/1a97b8c305039ae8d7196311c6b43ff8 to your computer and use it in GitHub Desktop.
Save akccakcctw/1a97b8c305039ae8d7196311c6b43ff8 to your computer and use it in GitHub Desktop.
檢測是否捲動到頁面底部
window.addEventListener('scroll', function() {
var pageHeight = document.documentElement.offsetHeight;
var windowHeight = window.innerHeight;
var scrollPosition = window.scrollY || window.pageYOffset || document.body.scrollTop + (document.documentElement && document.documentElement.scrollTop || 0);
console.log({pageHeight, windowHeight, scrollPosition});
if (pageHeight <= windowHeight + scrollPosition) {
console.log('At the bottom');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment