Fixed fullscreen lyrics alignment
This commit is contained in:
1 parent
cc0623ef4a
commit
4caa9135ee
1 file changed
+33
-33
@@ -15,31 +15,29 @@ const parsedLyrics = computed(() => {
|
|||||||
if (song.value.lyrics.synced) return parseLyrics(song.value.lyrics.text)
|
if (song.value.lyrics.synced) return parseLyrics(song.value.lyrics.text)
|
||||||
})
|
})
|
||||||
|
|
||||||
const lyricsRefs = useTemplateRef("lyrics")
|
const findLyricIndex = (time: number) => {
|
||||||
|
|
||||||
const activeIndex = computed(() => {
|
|
||||||
if (!parsedLyrics.value) return -1
|
if (!parsedLyrics.value) return -1
|
||||||
|
|
||||||
const time = secondsPlayed.value
|
const index = parsedLyrics.value.findIndex(
|
||||||
|
|
||||||
return parsedLyrics.value.findIndex(
|
|
||||||
(lyric, i) =>
|
(lyric, i) =>
|
||||||
lyric.time <= time &&
|
lyric.time <= time &&
|
||||||
(!parsedLyrics.value![i + 1] ||
|
(!parsedLyrics.value![i + 1] ||
|
||||||
parsedLyrics.value![i + 1]!.time > time),
|
parsedLyrics.value![i + 1]!.time > time),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return index
|
||||||
|
}
|
||||||
|
|
||||||
|
const activeIndex = computed(() => {
|
||||||
|
return findLyricIndex(secondsPlayed.value)
|
||||||
})
|
})
|
||||||
const scrollActiveIndex = computed(() => {
|
const scrollActiveIndex = computed(() => {
|
||||||
if (!parsedLyrics.value) return -1
|
if (!parsedLyrics.value) return -1
|
||||||
|
|
||||||
const time = secondsPlayed.value + animationDuration
|
const time = secondsPlayed.value + animationDuration
|
||||||
|
|
||||||
let index = parsedLyrics.value.findIndex(
|
let index = findLyricIndex(time)
|
||||||
(lyric, i) =>
|
if (index === -1 && time < parsedLyrics.value[0]!.time) index = 0
|
||||||
lyric.time <= time &&
|
|
||||||
(!parsedLyrics.value![i + 1] ||
|
|
||||||
parsedLyrics.value![i + 1]!.time > time),
|
|
||||||
)
|
|
||||||
|
|
||||||
if (index >= parsedLyrics.value.length - 1)
|
if (index >= parsedLyrics.value.length - 1)
|
||||||
index = parsedLyrics.value.length - 2
|
index = parsedLyrics.value.length - 2
|
||||||
@@ -73,24 +71,23 @@ watch(
|
|||||||
onMounted(() => window.addEventListener("resize", updateLyricsLayout))
|
onMounted(() => window.addEventListener("resize", updateLyricsLayout))
|
||||||
onUnmounted(() => window.removeEventListener("resize", updateLyricsLayout))
|
onUnmounted(() => window.removeEventListener("resize", updateLyricsLayout))
|
||||||
|
|
||||||
const transformY = computed(() => {
|
|
||||||
if (activeIndex.value < 0) return 0
|
|
||||||
|
|
||||||
let accumulatedHeight = 0
|
|
||||||
|
|
||||||
if (!lyricsRefs.value) return 0
|
|
||||||
|
|
||||||
for (let i = 0; i < scrollActiveIndex.value; i++) {
|
|
||||||
const el = lyricsRefs.value[i]
|
|
||||||
if (el) accumulatedHeight += el.getBoundingClientRect().height
|
|
||||||
}
|
|
||||||
|
|
||||||
return -accumulatedHeight
|
|
||||||
})
|
|
||||||
|
|
||||||
const containerRef = useTemplateRef("container-ref")
|
const containerRef = useTemplateRef("container-ref")
|
||||||
const outerRef = useTemplateRef("outer-ref")
|
const outerRef = useTemplateRef("outer-ref")
|
||||||
|
|
||||||
|
const transformY = computed(() => {
|
||||||
|
const lines = containerRef.value?.children
|
||||||
|
if (scrollActiveIndex.value < 0 || !lines?.length) return 0
|
||||||
|
|
||||||
|
const firstLyric = lines[0] as HTMLElement
|
||||||
|
const activeLyric = lines[scrollActiveIndex.value] as HTMLElement
|
||||||
|
if (!firstLyric || !activeLyric) return 0
|
||||||
|
|
||||||
|
return (
|
||||||
|
firstLyric.getBoundingClientRect().top -
|
||||||
|
activeLyric.getBoundingClientRect().bottom
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
const manualOffset = ref(0)
|
const manualOffset = ref(0)
|
||||||
const isScrolling = ref(false)
|
const isScrolling = ref(false)
|
||||||
|
|
||||||
@@ -100,7 +97,7 @@ const onWheel = (event: WheelEvent) => {
|
|||||||
if (!containerRef.value || !outerRef.value) return
|
if (!containerRef.value || !outerRef.value) return
|
||||||
|
|
||||||
if (!isScrolling.value) {
|
if (!isScrolling.value) {
|
||||||
manualOffset.value = transformY.value + offset + topFadeExtension
|
manualOffset.value = finalTransform.value
|
||||||
}
|
}
|
||||||
|
|
||||||
isScrolling.value = true
|
isScrolling.value = true
|
||||||
@@ -110,7 +107,7 @@ const onWheel = (event: WheelEvent) => {
|
|||||||
|
|
||||||
manualOffset.value -= delta
|
manualOffset.value -= delta
|
||||||
|
|
||||||
const maxTranslate = offset + topFadeExtension
|
const maxTranslate = finalTransform.value + offset
|
||||||
const lowerViewportLimit = Math.max(
|
const lowerViewportLimit = Math.max(
|
||||||
outerRef.value.offsetHeight,
|
outerRef.value.offsetHeight,
|
||||||
window.innerHeight - 300,
|
window.innerHeight - 300,
|
||||||
@@ -135,7 +132,10 @@ const onLyricClick = (time: number) => {
|
|||||||
const finalTransform = computed(() => {
|
const finalTransform = computed(() => {
|
||||||
if (isScrolling.value) return manualOffset.value
|
if (isScrolling.value) return manualOffset.value
|
||||||
|
|
||||||
return transformY.value + offset + topFadeExtension
|
const lyricsTop = top.value - topFadeExtension
|
||||||
|
const guideY = import.meta.client ? window.innerHeight * 0.45 : 0
|
||||||
|
const laterLyricOffset = scrollActiveIndex.value > 0 ? 100 : 0
|
||||||
|
return transformY.value + guideY - lyricsTop + laterLyricOffset
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -162,10 +162,9 @@ const finalTransform = computed(() => {
|
|||||||
v-for="(lyric, i) in parsedLyrics"
|
v-for="(lyric, i) in parsedLyrics"
|
||||||
:key="lyric.time"
|
:key="lyric.time"
|
||||||
:class="{
|
:class="{
|
||||||
active: i == scrollActiveIndex,
|
active: i == activeIndex,
|
||||||
past: i < scrollActiveIndex && !isScrolling,
|
past: i < activeIndex && !isScrolling,
|
||||||
}"
|
}"
|
||||||
ref="lyrics"
|
|
||||||
@click="onLyricClick(lyric.time)"
|
@click="onLyricClick(lyric.time)"
|
||||||
>
|
>
|
||||||
{{ lyric.text }}
|
{{ lyric.text }}
|
||||||
@@ -214,6 +213,7 @@ const finalTransform = computed(() => {
|
|||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: white;
|
color: white;
|
||||||
opacity: 0.4;
|
opacity: 0.4;
|
||||||
|
margin: 0;
|
||||||
padding: 10px 0;
|
padding: 10px 0;
|
||||||
transition:
|
transition:
|
||||||
opacity 0.1s ease,
|
opacity 0.1s ease,
|
||||||
|
|||||||
Reference in new issue
Block a user