1
0
mirror of https://github.com/zclzone/vue-naive-admin.git synced 2025-05-01 06:39:01 +08:00

feat: 添加切换主题的动画效果

This commit is contained in:
zclzone 2024-06-25 16:44:27 +08:00
parent c2ff434b9d
commit c87f56814e
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,34 @@
<template>
<i
class="mr-16 cursor-pointer"
:class="isDark ? 'i-fe:moon' : 'i-fe:sun'"
@click="toggleDark"
/>
</template>
<script setup>
import { useDark, useToggle } from '@vueuse/core'
import { useAppStore } from '@/store'
const appStore = useAppStore()
const isDark = useDark()
function toggleDark({ clientX, clientY }) {
const maxRadius = Math.hypot(
Math.max(clientX, window.innerWidth - clientX),
Math.max(clientY, window.innerHeight - clientY),
)
const style = document.documentElement.style
style.setProperty('--circle-x', `${clientX}px`)
style.setProperty('--circle-y', `${clientY}px`)
style.setProperty('--circle-r', `${maxRadius}px`)
function handler() {
appStore.toggleDark()
useToggle(isDark)()
}
document.startViewTransition
? document.startViewTransition(handler)
: handler()
}
</script>

View File

@ -72,3 +72,23 @@ body {
}
}
}
/* 切换主题的动画效果 */
::view-transition-old(root) {
animation: none;
mix-blend-mode: normal;
}
::view-transition-new(root) {
animation: 0.5s ease-in circle-animation;
mix-blend-mode: normal;
}
@keyframes circle-animation {
from {
clip-path: circle(0 at var(--circle-x) var(--circle-y));
}
to {
clip-path: circle(var(--circle-r) at var(--circle-x) var(--circle-y));
}
}