cap virtual scroll index before use
This commit is contained in:
parent
686a8e1cfc
commit
1640841013
1 changed files with 5 additions and 7 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue