From e11af90ed1e7ce99a7a3364b8ae20d6fd134fef9 Mon Sep 17 00:00:00 2001 From: Edward Tombre Date: Wed, 1 Mar 2023 18:35:10 +0100 Subject: [PATCH 1/5] Use a callback to make sure we have scrolled to the top of the page before scrolling to the chapter --- src/mixins/reader.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/mixins/reader.js b/src/mixins/reader.js index 6931210..2b62719 100644 --- a/src/mixins/reader.js +++ b/src/mixins/reader.js @@ -1,4 +1,3 @@ -import Vue from 'vue'; export default { methods: { async loadTop() { @@ -50,18 +49,25 @@ export default { if(!article) return null; return `chapter-element-${article.chapterId}`; }, - scrollToChapter(chapterId, offset = -100) { + scrollToChapter(chapterId, offset = -70) { let article = this.articles.find((a) => a.chapterId === chapterId); if (!article) return false; var self = this; - window.scrollTo(0,0); - if (chapterId >= 2) { - Vue.nextTick() - .then(() => { - let chapterElementRect = document.querySelector('#'+self.getElementName(article)).getBoundingClientRect(); - window.scrollTo(0, chapterElementRect.top + offset); - }); + const fireCallbackOnTopHit = function() { + if (window.scrollY == 0) { + window.removeEventListener('scroll', fireCallbackOnTopHit) + if (chapterId >= 2) { + self.$nextTick() + .then(() => { + let chapterElementRect = document.querySelector('#'+self.getElementName(article)).getBoundingClientRect(); + window.scrollTo(0, chapterElementRect.top + offset); + }); + } + } } + window.addEventListener('scroll', fireCallbackOnTopHit) + fireCallbackOnTopHit() + window.scrollTo(0,0); }, setCurrentChapter(chapterId) { if (this.isPublication) From da6618475df8a62d353441de0694f38968faa723 Mon Sep 17 00:00:00 2001 From: Edward Tombre Date: Wed, 1 Mar 2023 18:35:29 +0100 Subject: [PATCH 2/5] Fix numbering of chapter in sidebar --- src/components/layout/app-sidebar.vue | 1 + src/styles/style.scss | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/layout/app-sidebar.vue b/src/components/layout/app-sidebar.vue index c0990ac..13ce229 100644 --- a/src/components/layout/app-sidebar.vue +++ b/src/components/layout/app-sidebar.vue @@ -10,6 +10,7 @@
  1. {{chapter.title}}
    diff --git a/src/styles/style.scss b/src/styles/style.scss index d4af9eb..0705726 100644 --- a/src/styles/style.scss +++ b/src/styles/style.scss @@ -550,7 +550,7 @@ ol.chapters{ } &:before{ - content: counter(li); + content: attr(chapter); display: inline-block; position: absolute; From c2fe58e727288c7c03e1a45447b511422ff45f1a Mon Sep 17 00:00:00 2001 From: Edward Tombre Date: Wed, 1 Mar 2023 18:35:49 +0100 Subject: [PATCH 3/5] Use this instead of Vue on nextTick call --- src/components/reader/article-scroller.vue | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/reader/article-scroller.vue b/src/components/reader/article-scroller.vue index ef0dc8f..8443dbd 100644 --- a/src/components/reader/article-scroller.vue +++ b/src/components/reader/article-scroller.vue @@ -8,7 +8,6 @@