File tree Expand file tree Collapse file tree 4 files changed +42
-3
lines changed Expand file tree Collapse file tree 4 files changed +42
-3
lines changed Original file line number Diff line number Diff line change 1
1
/* 全局 CSS 变量 */
2
2
@import url ("./variables.css" );
3
+ /* View Transition */
4
+ @import url ("./view-transition.css" );
3
5
4
6
html {
5
7
height : 100% ;
Original file line number Diff line number Diff line change
1
+ /* 控制切换主题时的动画效果(只在较新的浏览器上生效,例如 Chrome 111+) */
2
+
3
+ ::view-transition-old (root ) {
4
+ animation : none;
5
+ mix-blend-mode : normal;
6
+ }
7
+
8
+ ::view-transition-new (root ) {
9
+ animation : 0.5s ease-in clip-animation;
10
+ mix-blend-mode : normal;
11
+ }
12
+
13
+ @keyframes clip-animation {
14
+ from {
15
+ clip-path : circle (0px at var (--mobvue-dark-x ) var (--mobvue-dark-y ));
16
+ }
17
+ to {
18
+ clip-path : circle (var (--mobvue-dark-r ) at var (--mobvue-dark-x ) var (--mobvue-dark-y ));
19
+ }
20
+ }
Original file line number Diff line number Diff line change 1
1
import { getIsDark , setIsDark } from "@@/utils/cache/local-storage"
2
+ import { setCssVar } from "@@/utils/css"
2
3
3
4
const isDark = ref < boolean > ( getIsDark ( ) === "true" )
4
5
6
+ function changeDark ( { clientX, clientY } : MouseEvent ) {
7
+ const maxRadius = Math . hypot (
8
+ Math . max ( clientX , window . innerWidth - clientX ) ,
9
+ Math . max ( clientY , window . innerHeight - clientY )
10
+ )
11
+ const documentElement = document . documentElement
12
+ setCssVar ( "--mobvue-dark-x" , `${ clientX } px` , documentElement )
13
+ setCssVar ( "--mobvue-dark-y" , `${ clientY } px` , documentElement )
14
+ setCssVar ( "--mobvue-dark-r" , `${ maxRadius } px` , documentElement )
15
+ const handler = ( ) => {
16
+ isDark . value = ! isDark . value
17
+ }
18
+ document . startViewTransition ? document . startViewTransition ( handler ) : handler ( )
19
+ }
20
+
5
21
/** 初始化 */
6
22
function initDark ( ) {
7
23
// watchEffect 来收集副作用
@@ -11,6 +27,7 @@ function initDark() {
11
27
} )
12
28
}
13
29
30
+ /** 黑暗模式 Composable */
14
31
export function useDark ( ) {
15
- return { isDark, initDark }
32
+ return { isDark, changeDark , initDark }
16
33
}
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ const router = useRouter()
7
7
8
8
const userStore = useUserStore ()
9
9
10
- const { isDark } = useDark ()
10
+ const { isDark, changeDark } = useDark ()
11
11
12
12
function onClick() {
13
13
showToast (" 更多功能,敬请期待 ~" )
@@ -37,7 +37,7 @@ function onLogout() {
37
37
<van-cell-group un-mb-8px >
38
38
<van-cell title =" 🌗 Dark Mode 黑暗模式" center >
39
39
<template #right-icon >
40
- <van-switch v- model =" isDark" size =" min(5.333vw, 40px)" />
40
+ <van-switch : model-value =" isDark" size =" min(5.333vw, 40px)" @click = " changeDark " />
41
41
</template >
42
42
</van-cell >
43
43
<van-cell title =" 📚 Documentation 文档教程" is-link url =" https://juejin.cn/column/7472609448201666599" />
You can’t perform that action at this time.
0 commit comments