Skip to content

Instantly share code, notes, and snippets.

@furenku
Created May 23, 2023 19:49
Show Gist options
  • Save furenku/1e230eb266375bb629edbdf0383aa1bd to your computer and use it in GitHub Desktop.
Save furenku/1e230eb266375bb629edbdf0383aa1bd to your computer and use it in GitHub Desktop.
infinite scroll
let scrollDebounce
function loadMore() {
// ...
}
function windowScroll() {
if( ! scrollDebounce ) {
scrollDebounce = setTimeout( function(){
const container = document.querySelector("#container")
if( window.scrollY > container.clientHeight - window.innerHeight ) {
loadMore()
}
scrollDebounce = null
}, 300 )
}
}
function setupInfiniteScroll() {
window.addEventListener("scroll", windowScroll)
}
setupInfiniteScroll()
loadMore()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment