cap virtual scroll index before use

This commit is contained in:
Shpuld Shpuldson 2020-03-18 14:23:37 +02:00
commit 1640841013

View file

@ -158,6 +158,7 @@ const Timeline = {
if (!this.virtualScrollingEnabled) return
const statuses = this.$refs.timeline.children
const cappedScrollIndex = Math.max(0, Math.min(this.virtualScrollIndex, statuses.length - 1))
if (statuses.length === 0) return
@ -173,12 +174,9 @@ const Timeline = {
// if we have a previous scroll index that can be used, test if it's
// closer than the previous approximation, use it if so
const virtualScrollIndexY = statuses[this.virtualScrollIndex].getBoundingClientRect().y
if (
this.virtualScrollIndex < statuses.length &&
Math.abs(err) > virtualScrollIndexY
) {
approxIndex = this.virtualScrollIndex
const virtualScrollIndexY = statuses[cappedScrollIndex].getBoundingClientRect().y
if (Math.abs(err) > virtualScrollIndexY) {
approxIndex = cappedScrollIndex
err = virtualScrollIndexY
}
@ -210,7 +208,7 @@ const Timeline = {
handleScroll: throttle(function (e) {
this.determineVisibleStatuses()
this.scrollLoad(e)
}, 100),
}, 150),
handleVisibilityChange () {
this.unfocused = document.hidden
}