Matery主题自定义(一)黑夜模式
Matery 主题自定义(一)黑夜模式
黑夜模式
作为一个前端学习者,自然懂得黑夜模式的重要性,可惜主题原生未提供,那就自己弄吧
个人博客作为效果参考:https://dreamruins.gitee.io/
设置基础样式
参考其他优秀产品的黑夜模式,得出共性:
- 那就是黑夜模式的背景一般不会是纯黑(#000);而是淡黑色,字体也不是纯白(#fff)而浅白色
- 图片亮度降低
下面就开始贴代码了
在 themes>hexo-theme-matery>source>css>matery.css
中加上下面的代码
1 | /* 字体颜色变灰白色 */ |
切换按钮
完成了背景、字体、图片的样式,就需要黑夜白天切换按钮了
在 themes>hexo-theme-matery>layout>_widget
中创建一个新的文件 day-night.ejs,在新建的文件中加入下面的代码
1 |
|
再在 themes>hexo-theme-matery>layout>layout.ejs
文件中引用一下
需要在 body 标签内部插入下面代码
1 | <%- partial('_widget/day-night.ejs') %> |
按钮样式
完成上面操作以后,就需要添加按钮样式和切换动画了,同样是在 themes>hexo-theme-matery>source>css>matery.css
中
1 | /* 黑夜模式动画 */ |
定时提示切换黑夜模式
如果浏览时间在晚上 7 点到晚上 8 之间,会提示用户切换到黑夜模式
在themes>hexo-theme-matery>source>js>matery.js
中添加下列代码
1 | //黑夜模式提醒开启功能 |
自动切换黑夜模式
如果浏览时间在晚上 8 点到早上 7 之间,会自动切换到黑夜模式
在themes>hexo-theme-matery>layout>layout.ejs
中添加下列代码(最好插入在<%- partial('_partial/day-night.ejs') %>
下面)
1 | //黑夜模式提醒开启功能 |
黑夜模式持久化
在
themes>hexo-theme-matery>layout>layout.ejs
中添加下列代码(最好插入在<%- partial('_partial/day-night.ejs') %>
下面)
1 | /* 模式判断 */ |
这样黑夜模式算是真正完成了
Matery 主题自定义持续更新中…
参考
-
感谢你赐予我前进的力量