25 lines
498 B
TypeScript
Raw Normal View History

2018-04-02 05:34:16 +00:00
export default class InfiniteScroller {
2017-10-16 10:56:46 +00:00
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()
}
}