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