mirror of
https://github.com/CaiJimmy/hugo-theme-stack.git
synced 2025-04-28 19:43:31 +08:00
fix(colorScheme): systemPreferScheme not initialized on start up
This commit is contained in:
parent
048a000f17
commit
01cc267ab1
@ -8,6 +8,10 @@ class StackColorScheme {
|
|||||||
constructor(toggleEl: HTMLElement) {
|
constructor(toggleEl: HTMLElement) {
|
||||||
this.bindMatchMedia();
|
this.bindMatchMedia();
|
||||||
this.currentScheme = this.getSavedScheme();
|
this.currentScheme = this.getSavedScheme();
|
||||||
|
if (window.matchMedia('(prefers-color-scheme: dark)').matches === true)
|
||||||
|
this.systemPreferScheme = 'dark'
|
||||||
|
else
|
||||||
|
this.systemPreferScheme = 'light';
|
||||||
|
|
||||||
this.dispatchEvent(document.documentElement.dataset.scheme as colorScheme);
|
this.dispatchEvent(document.documentElement.dataset.scheme as colorScheme);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user