Created
January 4, 2021 06:52
-
-
Save AliwerErgashev/ceea47e92587d72d4724a46881f70c9f to your computer and use it in GitHub Desktop.
detect dark mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { | |
// dark mode | |
} | |
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => { | |
const newColorScheme = e.matches ? "dark" : "light"; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment