fix: current lyric class apply on multiple lines of lyrics which has same content

This commit is contained in:
Alikia2x 2024-05-12 14:28:51 +08:00
parent 4422937707
commit b9243b35a6

View File

@ -11,8 +11,8 @@
let _refs: any[] = []; let _refs: any[] = [];
$: refs = _refs.filter(Boolean); $: refs = _refs.filter(Boolean);
function getClass(lyric: string, progress: number) { function getClass(lyricIndex: number, progress: number) {
if (lyric === currentLyric.text) return 'current-lyric'; if (lyricIndex === currentLyricIndex) return 'current-lyric';
else if (progress > currentLyric.endSeconds) return 'after-lyric'; else if (progress > currentLyric.endSeconds) return 'after-lyric';
else return 'previous-lyric'; else return 'previous-lyric';
} }
@ -62,7 +62,7 @@
{#if lyrics && originalLyrics} {#if lyrics && originalLyrics}
<div class="lyrics" style="overflow-y: auto"> <div class="lyrics" style="overflow-y: auto">
{#each lyrics as lyric, i} {#each lyrics as lyric, i}
<p bind:this={_refs[i]} class={getClass(lyric, progress)}> <p bind:this={_refs[i]} class={getClass(i, progress)}>
{lyric} {lyric}
</p> </p>
{/each} {/each}