Implemented scrolling
This commit is contained in:
1 parent
fd27fee6c7
commit
ab22cd6eb9
2 files changed
+45
-5
No files matched your search
@@ -54,7 +54,7 @@ onMounted(() => {
|
|||||||
<PlayerFullscreenTrackDisplay
|
<PlayerFullscreenTrackDisplay
|
||||||
:show-buttons="mouseMovedRecently"
|
:show-buttons="mouseMovedRecently"
|
||||||
/>
|
/>
|
||||||
<LyricsDisplay :animation-duration="0.2" />
|
<LyricsDisplay :animation-duration="0.2" :offset="150" />
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const { animationDuration } = defineProps<{ animationDuration: number }>()
|
const { animationDuration, offset } = defineProps<{
|
||||||
|
animationDuration: number
|
||||||
|
offset: number
|
||||||
|
}>()
|
||||||
|
|
||||||
const song = useSong()
|
const song = useSong()
|
||||||
const { secondsPlayed } = usePlayer()
|
const { secondsPlayed } = usePlayer()
|
||||||
@@ -55,8 +58,6 @@ watch(parsedLyrics, () => {
|
|||||||
resizeObserver.observe(trackDisplay)
|
resizeObserver.observe(trackDisplay)
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(() => {})
|
|
||||||
|
|
||||||
const transformY = computed(() => {
|
const transformY = computed(() => {
|
||||||
if (activeIndex.value < 0) return 0
|
if (activeIndex.value < 0) return 0
|
||||||
|
|
||||||
@@ -71,20 +72,59 @@ const transformY = computed(() => {
|
|||||||
|
|
||||||
return -accumulatedHeight
|
return -accumulatedHeight
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const containerRef = useTemplateRef("container-ref")
|
||||||
|
const outerRef = useTemplateRef("outer-ref")
|
||||||
|
|
||||||
|
const manualOffset = ref(0)
|
||||||
|
const isScrolling = ref(false)
|
||||||
|
|
||||||
|
let scrollingTimeout: any = null
|
||||||
|
|
||||||
|
const onWheel = (event: WheelEvent) => {
|
||||||
|
if (!containerRef.value || !outerRef.value) return
|
||||||
|
|
||||||
|
isScrolling.value = true
|
||||||
|
clearTimeout(scrollingTimeout)
|
||||||
|
|
||||||
|
const delta = event.deltaY
|
||||||
|
|
||||||
|
manualOffset.value -= delta
|
||||||
|
|
||||||
|
const maxTranslate = offset
|
||||||
|
const minTranslate =
|
||||||
|
-containerRef.value.scrollHeight + outerRef.value.offsetHeight
|
||||||
|
|
||||||
|
manualOffset.value = Math.min(
|
||||||
|
maxTranslate,
|
||||||
|
Math.max(minTranslate, manualOffset.value),
|
||||||
|
)
|
||||||
|
|
||||||
|
scrollingTimeout = setTimeout(() => (isScrolling.value = false), 3000)
|
||||||
|
}
|
||||||
|
|
||||||
|
const finalTransform = computed(() => {
|
||||||
|
if (isScrolling.value) return manualOffset.value
|
||||||
|
|
||||||
|
return transformY.value + offset
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
|
ref="outer-ref"
|
||||||
v-if="song && song.lyrics.synced"
|
v-if="song && song.lyrics.synced"
|
||||||
class="synced-lyrics-container"
|
class="synced-lyrics-container"
|
||||||
:style="{
|
:style="{
|
||||||
height: `${height}px`,
|
height: `${height}px`,
|
||||||
}"
|
}"
|
||||||
|
@wheel.prevent="onWheel"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
ref="container-ref"
|
||||||
class="synced-lyrics"
|
class="synced-lyrics"
|
||||||
:style="{
|
:style="{
|
||||||
transform: `translateY(${transformY + 150}px)`,
|
transform: `translateY(${finalTransform}px)`,
|
||||||
transition: `transform ${animationDuration}s ease`,
|
transition: `transform ${animationDuration}s ease`,
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in new issue
Block a user