Improve scrolling, discover page

This commit is contained in:
Jon Staab
2024-10-17 14:26:53 -07:00
parent 9c31b12d48
commit 4683fc4203
12 changed files with 90 additions and 74 deletions
+12 -8
View File
@@ -34,15 +34,19 @@ export const createScroller = ({
let done = false
const check = async () => {
// While we have empty space, fill it
const {scrollY, innerHeight} = window
const {scrollHeight, scrollTop} = element
const offset = Math.abs(scrollTop || scrollY)
const shouldLoad = offset + innerHeight + threshold > scrollHeight
const container = element.closest('.scroll-container')
// Only trigger loading the first time we reach the threshold
if (shouldLoad) {
await onScroll()
if (container) {
// While we have empty space, fill it
const {scrollY, innerHeight} = window
const {scrollHeight, scrollTop} = container
const offset = Math.abs(scrollTop || scrollY)
const shouldLoad = offset + innerHeight + threshold > scrollHeight
// Only trigger loading the first time we reach the threshold
if (shouldLoad) {
await onScroll()
}
}
// No need to check all that often