From 7ffcd3fe1b2f95125400c213ee4b7f544c68950e Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Tue, 12 Jul 2022 17:33:03 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=BF=D0=BE=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=20=D1=81=D0=BA=D1=80=D0=BE=D0=BB=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=B3=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RecentBooksPage/RecentBooksPage.vue | 60 +++++++++++++------ 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/client/components/Reader/RecentBooksPage/RecentBooksPage.vue b/client/components/Reader/RecentBooksPage/RecentBooksPage.vue index 51812a86..7f3b13c7 100644 --- a/client/components/Reader/RecentBooksPage/RecentBooksPage.vue +++ b/client/components/Reader/RecentBooksPage/RecentBooksPage.vue @@ -15,6 +15,10 @@ + + + + { + this.showBar(); + await this.updateTableData(); + await this.scrollToActiveBook(); + })(); } loadSettings() { @@ -474,10 +481,21 @@ class RecentBooksPage { return false; } + showBar() { + this.lastScrollTop1 = this.$refs.vsContainer.scrollTop; + this.$refs.header.style.position = 'sticky'; + this.$refs.header.style.top = 0; + } + onScroll() { const curScrollTop = this.$refs.vsContainer.scrollTop; - if (curScrollTop - this.lastScrollTop1 > 150) { + if (this.lockScroll) { + this.lastScrollTop1 = curScrollTop; + return; + } + + if (curScrollTop - this.lastScrollTop1 > 100) { this.$refs.header.style.top = `-${this.$refs.header.offsetHeight}px`; this.$refs.header.style.transition = 'top 0.2s ease 0s'; @@ -503,24 +521,28 @@ class RecentBooksPage { } async scrollToActiveBook() { - await this.$nextTick(); - - let activeIndex = -1; - let activeParentIndex = -1; - for (let i = 0; i < this.tableData.length; i++) { - const book = this.tableData[i]; - if (book.active) - activeIndex = i; - if (book.activeParent) - activeParentIndex = i; + this.lockScroll = true; + try { + let activeIndex = -1; + let activeParentIndex = -1; + for (let i = 0; i < this.tableData.length; i++) { + const book = this.tableData[i]; + if (book.active) + activeIndex = i; + if (book.activeParent) + activeParentIndex = i; - if (activeIndex >= 0 && activeParentIndex >= 0) - break; - } + if (activeIndex >= 0 && activeParentIndex >= 0) + break; + } - const index = (activeIndex >= 0 ? activeIndex : activeParentIndex); - if (index >= 0) { - this.$refs.virtualScroll.scrollTo(index, 'center'); + const index = (activeIndex >= 0 ? activeIndex : activeParentIndex); + if (index >= 0) { + this.$refs.virtualScroll.scrollTo(index, 'center'); + } + } finally { + await utils.sleep(100); + this.lockScroll = false; } }