项目
在 GitHub 查看
coliff/dark-mode-switch
关于
使用 Bootstrap Custom Switch 添加深色模式主题切换开关
开发工具实测星标增长
- 24小时
- 0
- 7天
- +1
- 15天
- +1
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文🌓 Dark Mode Switch
Add a dark-mode theme toggle with a Bootstrap Custom Switch.
- Uses localStorage to save preference
- Only 383 Bytes minified and gzipped!
Quick start
Several quick start options are available:
- Download the latest release
- Clone the repo
git clone https://github.com/coliff/dark-mode-switch.git - Install with npm
npm install dark-mode-switch - Install with yarn
yarn add dark-mode-switch
Usage
- Add your custom switch for the Dark Mode toggle followed by the
dark-mode-switch.min.jsscript:
Bootstrap 4.x
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="darkSwitch" />
<label class="custom-control-label" for="darkSwitch">Dark Mode</label>
</div>
<script src="dark-mode-switch.min.js"></script>
Bootstrap 5.x
<div class="form-check form-switch">
<input type="checkbox" class="form-check-input" id="darkSwitch" />
<label class="custom-control-label" for="darkSwitch">Dark Mode</label>
</div>
<script src="dark-mode-switch.min.js"></script>
- Edit the
dark-mode.cssto suit your site - the one included here is a basic example.
How it works
Turning dark mode on will add data-theme="dark" to the body tag. You can use CSS to target the elements on the page like so:
[data-theme="dark"] {
background-color: #111 !important;
color: #eee;
}
Demo
Browser Support
Works well with all the browsers supported by Bootstrap 4 and Bootstrap 5
To Enable DarkMode in Android Webview
- You need DOM Storage API in order to make this work with WebView.
- Inside OnCreate under WebView paste this line.
WebSettings.setDomStorageEnabled(true)
Credits
Created thanks to the excellent dark-theme and local storage tutorials over at codyhouse.co.
探索相关项目
加载中…