Skip to content

Commit

Permalink
fix: should scroll the lyrics immediately when navigate to the playin…
Browse files Browse the repository at this point in the history
…g page
  • Loading branch information
Clarkkkk committed Jun 22, 2024
1 parent d721c63 commit a31603e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/pages/PlayingNow/components/Lyrics.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, watch } from 'vue'
import { onActivated, onMounted, ref, watch } from 'vue'
import type { ApiLyric } from 'api'
import { storeToRefs } from 'pinia'
import { useLyricsStore, usePlaylistStore } from 'stores'
Expand All @@ -23,14 +23,19 @@ async function reloadLyrics() {
}
}
watch(lyricsCurrentIndex, (currentIndex) => {
if (!containerRef.value || currentIndex < 0) return
function onLiricsIndexChange(index: number) {
if (!containerRef.value || index < 0) return
containerRef.value.scroll({
top: currentIndex * 56,
top: index * 56,
behavior: 'auto'
})
}
watch(lyricsCurrentIndex, (currentIndex) => {
onLiricsIndexChange(currentIndex)
})
onMounted(() => onLiricsIndexChange(lyricsCurrentIndex.value))
onActivated(() => onLiricsIndexChange(lyricsCurrentIndex.value))
</script>

<template>
Expand Down

0 comments on commit a31603e

Please sign in to comment.