-
Notifications
You must be signed in to change notification settings - Fork 0
/
theme3.html
114 lines (94 loc) · 2.97 KB
/
theme3.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<html lang="en-us" dir="ltr" class="theme-third">
<head>
<title>theme switcher</title>
<style>
.theme-default {
--accent-color: #72f1b8;
--font-color: #34294f;
}
.theme-second {
--accent-color: #FFBF00;
--font-color: #59316B;
}
.theme-third {
--accent-color: #d9455f;
--font-color: #303960;
}
body {
background-color: var(--accent-color);
color: var(--font-color);
}
.color-select button {
-moz-appearance: none;
appearance: none;
border: 2px solid;
border-radius: 9999px;
cursor: pointer;
height: 20px;
margin: 0 0.8rem 0.8rem 0;
outline: 0;
width: 20px;
}
/* Style each swatch to match the corresponding theme */
.color-select button:nth-child(1) {
background: #72f1b8;
border-color: #34294f;
}
.color-select button:nth-child(2) {
background: #FFBF00;
border-color: #59316B;
}
.color-select button:nth-child(3) {
background: #d9455f;
border-color: #303960;
}
button:focus,
button:focus-within {
outline: 1px solid white;
}
</style>
</head>
<body>
<div class="color-select">
<button onclick="toggleDefaultTheme()"></button>
<button onclick="toggleSecondTheme()"></button>
<button onclick="toggleThirdTheme()"></button>
</div>
<h1>Hello World</h1>
<script>
// Set a given theme/color-scheme
function setTheme(themeName) {
localStorage.setItem('theme', themeName);
document.documentElement.className = themeName;
}
// Toggle between color themes
function toggleDefaultTheme() {
if (localStorage.getItem('theme') !== 'theme-default') {
setTheme('theme-default');
}
}
function toggleSecondTheme() {
if (localStorage.getItem('theme') !== 'theme-second') {
setTheme('theme-second');
}
}
function toggleThirdTheme() {
if (localStorage.getItem('theme') !== 'theme-third') {
setTheme('theme-third');
}
}
// Immediately set the theme on initial load
(function () {
if (localStorage.getItem('theme') === 'theme-default') {
setTheme('theme-default');
}
if (localStorage.getItem('theme') === 'theme-second') {
setTheme('theme-second');
}
if (localStorage.getItem('theme') === 'theme-third') {
setTheme('theme-third');
}
})();
</script>
</body>
</html>