frontend: avoid scrolling too soon when switching pages
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Simon Bruder 2019-07-05 05:25:33 +00:00
parent d9a5bcdd54
commit 021476bfa2
No known key found for this signature in database
GPG key ID: 6F03E0000CC5B62F

View file

@ -1,7 +1,7 @@
<template> <template>
<div class="reader" v-shortkey="{next: ['arrowleft'], prev: ['arrowright']}" @shortkey="navigation" :style="{ 'grid-template-columns': showSidebar ? 'auto 250px' : 'auto' }"> <div class="reader" v-shortkey="{next: ['arrowleft'], prev: ['arrowright']}" @shortkey="navigation" :style="{ 'grid-template-columns': showSidebar ? 'auto 250px' : 'auto' }">
<div> <div>
<img :style="{ width: pageWidth + '%' }" :src="info.pages[page]"> <img :style="{ width: pageWidth + '%' }" :src="info.pages[page]" @load="setScroll">
<!-- prefetching --> <!-- prefetching -->
<img style="display: none;" :src="info.pages[page-1]"> <img style="display: none;" :src="info.pages[page-1]">
<img style="display: none;" :src="info.pages[page+1]"> <img style="display: none;" :src="info.pages[page+1]">
@ -56,7 +56,9 @@ export default {
if (page >= 0 && page < this.info.pages.length) { if (page >= 0 && page < this.info.pages.length) {
this.$router.push({ query: { page: page + 1 } }) this.$router.push({ query: { page: page + 1 } })
} }
},
setScroll () {
// load saved scroll posotion, if available, reset to 0 otherwise // load saved scroll posotion, if available, reset to 0 otherwise
if (this.scrollPositions[this.page]) { if (this.scrollPositions[this.page]) {
window.scrollTo(0, this.scrollPositions[this.page]) window.scrollTo(0, this.scrollPositions[this.page])