how to disabled prefers-color-scheme in js

dark theme

https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme

https://web.dev/prefers-color-scheme/#supporting-dark-mode

if (window.matchMedia('(prefers-color-scheme)').media !== 'not all') {
console.log(' Dark mode is supported');
}

https://gosink.in/javascript-css-toggle-dark-light-theme-based-on-your-users-preferred-scheme/

data-user-color-scheme

const applySetting = passedSetting => {
let currentSetting = passedSetting || localStorage.getItem(STORAGE_KEY); if (currentSetting) {
document.documentElement.setAttribute('data-user-color-scheme', currentSetting);
setButtonLabelAndStatus(currentSetting);
} else {
setButtonLabelAndStatus(getCSSCustomProp(COLOR_MODE_KEY));
}
};

https://codepen.io/xgqfrms/pen/qBbdbbJ?editors=1010

See the Pen user controlled dark mode & them toggole by xgqfrms
(@xgqfrms) on CodePen.

document.documentElement.setAttribute

https://stackoverflow.com/questions/56300132/how-to-over-ride-css-prefers-color-scheme-setting

// root/default variables
:root {
--font-color: #000;
--link-color:#1C75B9;
--link-white-color:#fff;
--bg-color: rgb(243,243,243);
}
//dark theme
[data-theme="dark"] {
--font-color: #c1bfbd;
--link-color:#0a86da;
--link-white-color:#c1bfbd;
--bg-color: #333;
}
//the redundancy is for backwards compatibility with browsers that do not support CSS variables.
body
{
color:#000;
color:var(--font-color);
background:rgb(243,243,243);
background:var(--bg-color);
}

document.documentElement.setAttribute('data-theme', 'light');

html customize element & dark theme

https://codepen.io/xgqfrms/pen/eYJBBVB

See the Pen html customize element & dark theme by xgqfrms
(@xgqfrms) on CodePen.

https://developers.google.com/web/fundamentals/performance/critical-rendering-path/render-tree-construction?hl=zh-cn

js toggle theme


xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


最新文章

  1. python之系统性能信息模块psutil
  2. 8、java继承中的this和super的应用
  3. WIN7 X64 如何运行debug
  4. 【BZOJ】1002: [FJOI2007]轮状病毒 递推+高精度
  5. hadoop之mapreduse 在Eclipse下的调试环境篇
  6. TensorFlow-Bitcoin-Robot:一个基于 TensorFlow LSTM 模型的 Bitcoin 价格预测机器人
  7. 5月11日——IOS下如何检测用户是否安装微信
  8. 20135337——linux实践三:ELF文件格式分析(32位系统)
  9. 大数据开发实战:HDFS和MapReduce优缺点分析
  10. c# 通过html导出pdf,带分页
  11. AxWebBrowser 实现的多进程浏览器 (一)
  12. 那些年我们爬过的山 - mybatis批量导入
  13. Java Spring-JdbcTemplate
  14. 分享一个电子发票信息提取工具(Python)
  15. python之九九乘法表
  16. Maven-Dependency Mechanism
  17. JAVA 遍历文件夹下的所有文件(递归调用)
  18. 轻量级批量管理工具pssh
  19. rpm、yum命令
  20. wireshark问题现象分析

热门文章

  1. 将ffmpeg编译为wasm版本且在浏览器中运行
  2. HA工作机制
  3. 美团配送A/B评估体系建设与实践
  4. pycharm设置头文件模板(for mac)
  5. H5 的直播协议和视频监控方案
  6. CCF-命令行选项(模拟)
  7. COS数据处理WebP压缩 | 减少70%图像大小
  8. Codeforces Round #673 (Div. 2) C. k-Amazing Numbers(思维)
  9. F(x) HDU - 4734
  10. [Golang]-4 错误处理、Panic、Defer