From d47f41e1e0d303c19d46bb20bc71030397d33da3 Mon Sep 17 00:00:00 2001 From: Valerii Tikhomirov Date: Mon, 29 May 2023 21:34:44 +0300 Subject: [PATCH] fix: scroll position after top-direction loading --- src/utils.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utils.js b/src/utils.js index 6c478f6..53c9b84 100644 --- a/src/utils.js +++ b/src/utils.js @@ -74,22 +74,22 @@ export const loopTracker = { }; export const scrollBarStorage = { - key: '_infiniteScrollHeight', + key: '_infiniteScrollPosition', getScrollElm(elm) { return elm === window ? document.documentElement : elm; }, save(elm) { const target = this.getScrollElm(elm); - // save scroll height on the scroll parent - target[this.key] = target.scrollHeight; + // save scroll height and top position on the scroll parent + target[this.key] = [target.scrollHeight, target.scrollTop]; }, restore(elm) { const target = this.getScrollElm(elm); /* istanbul ignore else */ - if (typeof target[this.key] === 'number') { - target.scrollTop = target.scrollHeight - target[this.key] + target.scrollTop; + if (typeof target[this.key][0] === 'number' && typeof target[this.key][1] === 'number') { + target.scrollTop = target.scrollHeight - target[this.key][0] + target[this.key][1]; } this.remove(target);