Added infinite scrolling
This commit is contained in:
25
scripts/InfiniteScroller.ts
Normal file
25
scripts/InfiniteScroller.ts
Normal file
@ -0,0 +1,25 @@
|
||||
export class InfiniteScroller {
|
||||
container: HTMLElement
|
||||
threshold: number
|
||||
|
||||
constructor(container, threshold) {
|
||||
this.container = container
|
||||
this.threshold = threshold
|
||||
|
||||
this.container.addEventListener("scroll", e => {
|
||||
if(this.container.scrollTop + this.container.clientHeight >= this.container.scrollHeight - threshold) {
|
||||
this.loadMore()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
loadMore() {
|
||||
let button = document.getElementById("load-more-button")
|
||||
|
||||
if(!button) {
|
||||
return
|
||||
}
|
||||
|
||||
button.click()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user