Skip to content

Commit

Permalink
fix: notes scroll to up on page change
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Oct 27, 2023
1 parent 28c38c8 commit 40fb6f0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/client/internals/NotesView.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { useHead } from '@vueuse/head'
import { computed } from 'vue'
import { computed, ref, watch } from 'vue'
import { useLocalStorage } from '@vueuse/core'
import { configs } from '../env'
import { sharedState } from '../state/shared'
Expand All @@ -17,10 +17,16 @@ useHead({
const { isFullscreen, toggle: toggleFullscreen } = fullscreen
const scroller = ref<HTMLDivElement>()
const fontSize = useLocalStorage('slidev-notes-font-size', 18)
const pageNo = computed(() => sharedState.lastUpdate?.type === 'viewer' ? sharedState.viewerPage : sharedState.page)
const currentRoute = computed(() => rawRoutes.find(i => i.path === `${pageNo.value}`))
watch(pageNo, () => {
scroller.value?.scrollTo({ left: 0, top: 0, behavior: 'smooth' })
window.scrollTo({ left: 0, top: 0, behavior: 'smooth' })
})
function increaseFontSize() {
fontSize.value = fontSize.value + 1
}
Expand All @@ -37,6 +43,7 @@ function decreaseFontSize() {
/>
<div class="h-full flex flex-col">
<div
ref="scroller"
class="px-5 flex-auto h-full overflow-auto"
:style="{ fontSize: `${fontSize}px` }"
>
Expand Down

0 comments on commit 40fb6f0

Please sign in to comment.