From 6e4cdd22f9e262e671b166783d089ec971411b23 Mon Sep 17 00:00:00 2001 From: kjqwer <2990346238@qq.com> Date: Sun, 7 Dec 2025 21:24:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E9=A2=98=E6=A0=B7=E5=BC=8F=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 28 ++++++++++++--- src/components/icons/IconTheme.vue | 55 ++++++++++++++++++++++++++++-- 2 files changed, 77 insertions(+), 6 deletions(-) diff --git a/src/App.vue b/src/App.vue index 790f7ab..a77f038 100644 --- a/src/App.vue +++ b/src/App.vue @@ -58,6 +58,12 @@ function toggleTheme(event: MouseEvent) { return } + const willBeDark = !isDark.value + + if (willBeDark) { + document.documentElement.classList.add('theme-transition-reverse') + } + const x = event.clientX const y = event.clientY const endRadius = Math.hypot( @@ -66,7 +72,7 @@ function toggleTheme(event: MouseEvent) { ) const transition = document.startViewTransition(async () => { - isDark.value = !isDark.value + isDark.value = willBeDark localStorage.setItem('theme', isDark.value ? 'dark' : 'light') updateTheme() await nextTick() @@ -77,17 +83,25 @@ function toggleTheme(event: MouseEvent) { `circle(0px at ${x}px ${y}px)`, `circle(${endRadius}px at ${x}px ${y}px)` ] + + const isReverse = willBeDark + document.documentElement.animate( { - clipPath: clipPath, + clipPath: isReverse ? [...clipPath].reverse() : clipPath, }, { duration: 400, easing: 'ease-out', - pseudoElement: '::view-transition-new(root)', + pseudoElement: isReverse ? '::view-transition-old(root)' : '::view-transition-new(root)', + fill: 'forwards', } ) }) + + transition.finished.then(() => { + document.documentElement.classList.remove('theme-transition-reverse') + }) } function updateTheme() { @@ -192,7 +206,6 @@ const bgModeLabel = computed(() => {