how to disabled prefers-color-scheme in js & dark theme
2024-09-02 22:23:05
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.
js toggle theme
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
最新文章
- python之系统性能信息模块psutil
- 8、java继承中的this和super的应用
- WIN7 X64 如何运行debug
- 【BZOJ】1002: [FJOI2007]轮状病毒 递推+高精度
- hadoop之mapreduse 在Eclipse下的调试环境篇
- TensorFlow-Bitcoin-Robot:一个基于 TensorFlow LSTM 模型的 Bitcoin 价格预测机器人
- 5月11日——IOS下如何检测用户是否安装微信
- 20135337——linux实践三:ELF文件格式分析(32位系统)
- 大数据开发实战:HDFS和MapReduce优缺点分析
- c# 通过html导出pdf,带分页
- AxWebBrowser 实现的多进程浏览器 (一)
- 那些年我们爬过的山 - mybatis批量导入
- Java Spring-JdbcTemplate
- 分享一个电子发票信息提取工具(Python)
- python之九九乘法表
- Maven-Dependency Mechanism
- JAVA 遍历文件夹下的所有文件(递归调用)
- 轻量级批量管理工具pssh
- rpm、yum命令
- wireshark问题现象分析