From 54f73fc1b806bb48a9255c85000213e6f71aed54 Mon Sep 17 00:00:00 2001 From: Riceball LEE Date: Sat, 29 Sep 2018 20:51:24 +0800 Subject: [PATCH 01/15] chore: need to restore the scroll position when direction is top --- src/components/InfiniteLoading.vue | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/components/InfiniteLoading.vue b/src/components/InfiniteLoading.vue index f5f3496..4d8c4ac 100644 --- a/src/components/InfiniteLoading.vue +++ b/src/components/InfiniteLoading.vue @@ -75,6 +75,19 @@ const evt3rdArg = (() => { return result; })(); +function restoreScrollPos() { + if (this.lastHeight) { + const vClientRect = this.scrollParent.getBoundingClientRect(); + if (this.scrollParent.scrollHeight - this.lastHeight >= vClientRect.height) { + this.scrollParent.scrollTop = this.distance + + this.scrollParent.scrollHeight - this.lastHeight; + } else { + this.scrollParent.scrollTop = this.distance + 1; + } + this.lastHeight = 0; + } +} + export default { name: 'InfiniteLoading', data() { @@ -151,6 +164,7 @@ export default { this.$on('$InfiniteLoading:loaded', (ev) => { this.isFirstLoad = false; + restoreScrollPos.call(this); if (this.isLoading) { this.$nextTick(this.attemptLoad.bind(null, true)); @@ -164,6 +178,7 @@ export default { this.$on('$InfiniteLoading:complete', (ev) => { this.isLoading = false; this.isComplete = true; + restoreScrollPos.call(this); // force re-complation computed properties to fix the problem of get slot text delay this.$nextTick(() => { @@ -178,6 +193,7 @@ export default { }); this.$on('$InfiniteLoading:reset', () => { + this.lastHeight = 0; this.isLoading = false; this.isComplete = false; this.isFirstLoad = true; @@ -259,6 +275,8 @@ export default { if (this.continuousCallTimes > LOOP_CHECK_MAX_CALLS) { console.error(ERRORS.INFINITE_LOOP); this.infiniteLoopChecked = true; + // Avoid the Chrome Browser frozen. + // this.$emit('$InfiniteLoading:complete', { target: this }); } } } else { @@ -312,6 +330,7 @@ export default { } }, }; +