Created
May 23, 2023 19:49
-
-
Save furenku/1e230eb266375bb629edbdf0383aa1bd to your computer and use it in GitHub Desktop.
infinite scroll
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
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