diff --git a/src/renderer/layout/components/MusicFull.vue b/src/renderer/layout/components/MusicFull.vue index 2f5b5f0..38a51c1 100644 --- a/src/renderer/layout/components/MusicFull.vue +++ b/src/renderer/layout/components/MusicFull.vue @@ -227,9 +227,21 @@ const isVisible = computed({ }); // 歌词滚动方法 -const lrcScroll = (behavior: ScrollBehavior = 'smooth') => { +const lrcScroll = (behavior: ScrollBehavior = 'smooth', forceTop: boolean = false) => { + if (!isVisible.value || !lrcSider.value) return; + + if (forceTop) { + lrcSider.value.scrollTo({ + top: 0, + behavior + }); + return; + } + + if (isMouse.value) return; + const nowEl = document.querySelector(`#music-lrc-text-${nowIndex.value}`) as HTMLElement; - if (isVisible.value && !isMouse.value && nowEl && lrcSider.value) { + if (nowEl) { const containerHeight = lrcSider.value.$el.clientHeight; const elementTop = nowEl.offsetTop; const scrollTop = elementTop - containerHeight / 2 + nowEl.clientHeight / 2; @@ -479,6 +491,13 @@ onMounted(() => { } }); +// 添加对 playMusic 的监听 +watch(playMusic, () => { + nextTick(() => { + lrcScroll('instant', true); + }); +}); + defineExpose({ lrcScroll, config diff --git a/src/renderer/utils/linearColor.ts b/src/renderer/utils/linearColor.ts index e46ad4d..08334ec 100644 --- a/src/renderer/utils/linearColor.ts +++ b/src/renderer/utils/linearColor.ts @@ -152,7 +152,6 @@ export const getTextColors = (gradient: string = ''): ITextColors => { if (!gradient) return defaultColors; const colors = parseGradient(gradient); - console.log('colors', colors); if (!colors.length) return defaultColors; const mainColor = colors.length === 1 ? colors[0] : colors[1] || colors[0];