mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-25 03:02:21 +00:00
Merge pull request #1002 from zhidaoliu/gh-pages
feat: add change theme
This commit is contained in:
commit
dd892f89ac
26
css/app.css
26
css/app.css
@ -340,6 +340,32 @@ input.searchButton {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#theme {
|
||||||
|
display: none;
|
||||||
|
position: fixed;
|
||||||
|
|
||||||
|
height: 17px;
|
||||||
|
width: 70px;
|
||||||
|
top: 70px;
|
||||||
|
|
||||||
|
margin-left: 930px;
|
||||||
|
margin-top: 0px;
|
||||||
|
|
||||||
|
color: #FFF;
|
||||||
|
line-height: 17px;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 10px;
|
||||||
|
|
||||||
|
|
||||||
|
border-radius: 5px;
|
||||||
|
background-color: #AAA;
|
||||||
|
}
|
||||||
|
|
||||||
|
#theme:hover {
|
||||||
|
background-color: #444;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
#loading, #error {
|
#loading, #error {
|
||||||
display: none;
|
display: none;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
<!-- optional -->
|
<!-- optional -->
|
||||||
<div id="back_to_top">back to top</div>
|
<div id="back_to_top">back to top</div>
|
||||||
<div id="edit">edit</div>
|
<div id="edit">edit</div>
|
||||||
|
<div id="theme">theme</div>
|
||||||
<div id="loading">Loading ...</div>
|
<div id="loading">Loading ...</div>
|
||||||
<div id="error">Oops! ... File not found!</div>
|
<div id="error">Oops! ... File not found!</div>
|
||||||
<div id="flip"><div id="pageup">上一章</div><div id="pagedown">下一章</div></div>
|
<div id="flip"><div id="pageup">上一章</div><div id="pagedown">下一章</div></div>
|
||||||
|
33
js/ditto.js
33
js/ditto.js
@ -4,6 +4,7 @@ var ditto = {
|
|||||||
sidebar_id: "#sidebar",
|
sidebar_id: "#sidebar",
|
||||||
edit_id: "#edit",
|
edit_id: "#edit",
|
||||||
back_to_top_id: "#back_to_top",
|
back_to_top_id: "#back_to_top",
|
||||||
|
theme_id: "#theme",
|
||||||
loading_id: "#loading",
|
loading_id: "#loading",
|
||||||
error_id: "#error",
|
error_id: "#error",
|
||||||
|
|
||||||
@ -11,6 +12,7 @@ var ditto = {
|
|||||||
sidebar: true,
|
sidebar: true,
|
||||||
edit_button: true,
|
edit_button: true,
|
||||||
back_to_top_button: true,
|
back_to_top_button: true,
|
||||||
|
theme_button: true,
|
||||||
save_progress: true, // 保存阅读进度
|
save_progress: true, // 保存阅读进度
|
||||||
search_bar: true,
|
search_bar: true,
|
||||||
|
|
||||||
@ -59,6 +61,10 @@ function initialize() {
|
|||||||
init_edit_button();
|
init_edit_button();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ditto.theme_button) {
|
||||||
|
init_theme_button();
|
||||||
|
}
|
||||||
|
|
||||||
// page router
|
// page router
|
||||||
router();
|
router();
|
||||||
$(window).on('hashchange', router);
|
$(window).on('hashchange', router);
|
||||||
@ -133,12 +139,39 @@ function searchbar_listener(event) {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function init_theme_button() {
|
||||||
|
$(ditto.theme_id).show();
|
||||||
|
// 默认主题
|
||||||
|
var currFontColor = localStorage.getItem('fontColor') || '#0d141e';
|
||||||
|
var currBgColor = localStorage.getItem('bgColor') || '#ffffff';
|
||||||
|
$('body').css({
|
||||||
|
color: currFontColor,
|
||||||
|
backgroundColor: currBgColor
|
||||||
|
})
|
||||||
|
$(ditto.theme_id).on('click', changeTheme);
|
||||||
|
}
|
||||||
|
|
||||||
function init_back_to_top_button() {
|
function init_back_to_top_button() {
|
||||||
$(ditto.back_to_top_id).show();
|
$(ditto.back_to_top_id).show();
|
||||||
$(ditto.back_to_top_id).on('click', goTop);
|
$(ditto.back_to_top_id).on('click', goTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 改变主题
|
||||||
|
function changeTheme() {
|
||||||
|
var fontColor = localStorage.getItem('fontColor') || '#0d141e';
|
||||||
|
var bgColor = localStorage.getItem('bgColor') || '#ffffff';
|
||||||
|
var fontColors = ['#0d141e', '#020000', '#020702', '#d0d3d8'];
|
||||||
|
var bgColors = ['#ffffff', '#f6f0da', '#c0edc6', '#1f2022'];
|
||||||
|
var currIndex = bgColors.indexOf(bgColor);
|
||||||
|
var nextIndex = (currIndex + 1) >= bgColors.length ? 0 : currIndex + 1;
|
||||||
|
$('body').css({
|
||||||
|
color: fontColors[nextIndex],
|
||||||
|
backgroundColor: bgColors[nextIndex],
|
||||||
|
});
|
||||||
|
localStorage.setItem('fontColor', fontColors[nextIndex]);
|
||||||
|
localStorage.setItem('bgColor', bgColors[nextIndex]);
|
||||||
|
}
|
||||||
|
|
||||||
function goTop(e) {
|
function goTop(e) {
|
||||||
if(e) e.preventDefault();
|
if(e) e.preventDefault();
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user