Returns true
if the user color scheme preference is light
, false
otherwise.
Use window.matchMedia()
with the appropriate media query to check the user color scheme preference.
代码片段
const prefersLightColorScheme = () =>
window && window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches;
使用样例
prefersLightColorScheme(); // true