Skip to content

Commit 7c5f60f

Browse files
committed
update
1 parent c9fd931 commit 7c5f60f

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

Web-API/matchMedia-跟随系统的主题切换/README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
###
44

5-
### — 穆贵林
5+
### — 穆贵林
66

7-
2025年02月28日
7+
​ 2025年03月6日
8+
9+
###### CSDN:[JS媒体查询之matchMedia API 实现跟随系统主题色切换效果](https://blog.csdn.net/muguli2008/article/details/144797009)
810

911

1012

@@ -53,7 +55,7 @@ Window 的 [matchMedia()](https://developer.mozilla.org/zh-CN/docs/Web/API/Windo
5355
--bg-color: #333;
5456
}
5557
56-
html[data-theme="ligth"] {
58+
html[data-theme="light"] {
5759
--text-color: #333;
5860
--bg-color: #fff;
5961
}
@@ -101,7 +103,7 @@ Window 的 [matchMedia()](https://developer.mozilla.org/zh-CN/docs/Web/API/Windo
101103
<hr>
102104

103105
<select name="theme" id="theme">
104-
<option value="ligth">亮色</option>
106+
<option value="light">亮色</option>
105107
<option value="dark">暗色</option>
106108
<option value="os">系统跟随</option>
107109
<option value="red">红色</option>
@@ -119,13 +121,13 @@ Window 的 [matchMedia()](https://developer.mozilla.org/zh-CN/docs/Web/API/Windo
119121
120122
// 设置主题
121123
const setTheme = (theme) => {
122-
document.documentElement.setAttribute('data-theme', Object.prototype.toString.call(theme) === '[object MediaQueryListEvent]' ? metch.matches ? 'dark' : 'ligth' : theme);
124+
document.documentElement.setAttribute('data-theme', Object.prototype.toString.call(theme) === '[object MediaQueryListEvent]' ? metch.matches ? 'dark' : 'light' : theme);
123125
};
124126
125127
// 监听主题切换
126128
theme.addEventListener('change', (e) => {
127129
if ('os' === e.target.value) {
128-
setTheme(metch.matches ? 'dark' : 'ligth');
130+
setTheme(metch.matches ? 'dark' : 'light');
129131
// 监听系统主题切换
130132
metch.addEventListener('change', setTheme);
131133
} else {
@@ -202,7 +204,7 @@ export function useTheme() {
202204
<h1>JS媒体查询之matchMedia API 实现跟随系统主题色切换效果</h1>
203205
<hr>
204206
<select v-model="theme">
205-
<option value="ligth">亮色</option>
207+
<option value="light">亮色</option>
206208
<option value="dark">暗色</option>
207209
<option value="os">系统跟随</option>
208210
<option value="red">红色</option>
@@ -223,7 +225,7 @@ export function useTheme() {
223225
--bg-color: #333;
224226
}
225227
226-
html[data-theme="ligth"] {
228+
html[data-theme="light"] {
227229
--text-color: #333;
228230
--bg-color: #fff;
229231
}
5.89 KB
Binary file not shown.

Web-API/matchMedia-跟随系统的主题切换/theme.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
--bg-color: #333;
1717
}
1818

19-
html[data-theme="ligth"] {
19+
html[data-theme="light"] {
2020
--text-color: #333;
2121
--bg-color: #fff;
2222
}
@@ -64,7 +64,7 @@ <h1>JS媒体查询之matchMedia API 实现跟随系统主题色切换效果</h1>
6464
<hr>
6565

6666
<select name="theme" id="theme">
67-
<option value="ligth">亮色</option>
67+
<option value="light">亮色</option>
6868
<option value="dark">暗色</option>
6969
<option value="os">系统跟随</option>
7070
<option value="red">红色</option>
@@ -82,13 +82,13 @@ <h5>注:如果想要在系统主题色切换时,也跟着一起切换,请
8282

8383
// 设置主题
8484
const setTheme = (theme) => {
85-
document.documentElement.setAttribute('data-theme', Object.prototype.toString.call(theme) === '[object MediaQueryListEvent]' ? metch.matches ? 'dark' : 'ligth' : theme);
85+
document.documentElement.setAttribute('data-theme', Object.prototype.toString.call(theme) === '[object MediaQueryListEvent]' ? metch.matches ? 'dark' : 'light' : theme);
8686
};
8787

8888
// 监听主题切换
8989
theme.addEventListener('change', (e) => {
9090
if ('os' === e.target.value) {
91-
setTheme(metch.matches ? 'dark' : 'ligth');
91+
setTheme(metch.matches ? 'dark' : 'light');
9292
// 监听系统主题切换
9393
metch.addEventListener('change', setTheme);
9494
} else {

0 commit comments

Comments
 (0)