From 16408410135955036de261819667f88561a2e488 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Wed, 18 Mar 2020 14:23:37 +0200 Subject: [PATCH] cap virtual scroll index before use --- src/components/timeline/timeline.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js index 33e3e944d..9737be233 100644 --- a/src/components/timeline/timeline.js +++ b/src/components/timeline/timeline.js @@ -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 }