Make chapter section scroll to current chapter when scroll into view port when expanded (#4725)
* * Make chapter section scroll to current chapter when scroll into view port when expanded * * Use existing element instead of new dummy element
This commit is contained in:
@@ -33,7 +33,27 @@ export default defineComponent({
|
||||
|
||||
compact: function () {
|
||||
return !this.chapters[0].thumbnail
|
||||
}
|
||||
},
|
||||
|
||||
observeVisibilityOptions() {
|
||||
return {
|
||||
callback: (isVisible, _entry) => {
|
||||
// This is also fired when **hidden**
|
||||
// No point doing anything if not visible
|
||||
if (!isVisible) { return }
|
||||
// Only auto scroll when expanded
|
||||
if (!this.showChapters) { return }
|
||||
|
||||
this.scrollToCurrentChapter()
|
||||
},
|
||||
intersection: {
|
||||
// Only when it intersects with N% above bottom
|
||||
rootMargin: '0% 0% 0% 0%',
|
||||
},
|
||||
// Callback responsible for scolling to current chapter multiple times
|
||||
once: false,
|
||||
}
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
currentChapterIndex: function (value) {
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
<div
|
||||
v-show="showChapters"
|
||||
ref="chaptersWrapper"
|
||||
v-observe-visibility="observeVisibilityOptions"
|
||||
class="chaptersWrapper"
|
||||
:class="{ compact }"
|
||||
@keydown.arrow-up.stop.prevent="navigateChapters('up')"
|
||||
|
||||
Reference in New Issue
Block a user