检测系统的主题色

  1. window.addEventListener('theme-mode', event =>{
  2. if(event.mode == 'dark'){}
  3. if(event.mode == 'light'){}
  4. })
  5. window.matchMedia('(prefers-color-scheme: dark)') .addEventListener('change', event => {
  6. if (event.matches) {} // dark mode
  7. })