-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmode-switcher.html
More file actions
228 lines (198 loc) · 7.41 KB
/
mode-switcher.html
File metadata and controls
228 lines (198 loc) · 7.41 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Accessible Window Mode Toggle</title>
<style>
:root {
--bg-light: #f4f7f6;
--bg-dark: #0f172a;
--window-border: #5d4037;
--day-sky: #87CEEB;
--night-sky: #1e293b;
--focus-glow: #2563eb;
--link-color: #2563eb;
}
body {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
transition: background 0.6s cubic-bezier(0.4, 0, 0.2, 1);
background-color: var(--bg-light);
font-family: 'Segoe UI', system-ui, sans-serif;
}
body.dark-mode {
background-color: var(--bg-dark);
color: #f1f5f9;
}
/* Adjust link colors for dark mode */
body.dark-mode footer a {
color: #94a3b8;
}
.window-container {
text-align: center;
}
/* The Main Switch */
.switch {
position: relative;
display: inline-block;
width: 140px;
height: 80px;
}
/* Visually hide the checkbox but keep it in the focus order */
.switch input {
opacity: 0;
width: 0;
height: 0;
position: absolute;
}
/* Focus State for Keyboard Users */
.switch input:focus-visible + .slider {
outline: 3px solid var(--focus-glow);
outline-offset: 4px;
}
/* The Window Frame & Sky */
.slider {
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
background-color: var(--day-sky);
transition: 0.5s;
border: 6px solid var(--window-border);
border-radius: 12px;
overflow: hidden;
box-shadow: 0 10px 25px rgba(0,0,0,0.1);
cursor: pointer;
}
/* Window Panes - Increased z-index to 20 */
.panes::before, .panes::after {
content: "";
position: absolute;
background: var(--window-border);
z-index: 20; /* Moved in front of the handle */
}
.panes::before { width: 100%; height: 4px; top: 50%; left: 0; transform: translateY(-50%); }
.panes::after { height: 100%; width: 4px; left: 50%; top: 0; transform: translateX(-50%); }
/* The Handle (Sun/Moon) - Decreased z-index to 15 (or lower) */
.handle {
position: absolute;
height: 44px;
width: 44px;
left: 8px;
top: 12px;
background-color: #FFD700;
transition: 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
border-radius: 50%;
z-index: 15; /* Now sits behind the panes */
box-shadow: 0 0 20px #fff176;
}
/* Clouds */
.cloud {
position: absolute;
background: white;
border-radius: 50px;
opacity: 0.8;
transition: 0.5s;
z-index: 5;
}
.cloud::before, .cloud::after {
content: '';
position: absolute;
background: white;
border-radius: 50%;
}
.c1 { width: 40px; height: 15px; top: 15px; left: 10px; animation: float 4s infinite ease-in-out; }
.c1::before { width: 20px; height: 20px; top: -10px; left: 5px; }
.c1::after { width: 15px; height: 15px; top: -7px; left: 18px; }
.c2 { width: 30px; height: 10px; top: 45px; left: 70px; animation: float 6s infinite ease-in-out reverse; }
.c2::before { width: 15px; height: 15px; top: -8px; left: 4px; }
@keyframes float {
0%, 100% { transform: translateX(0); }
50% { transform: translateX(10px); }
}
/* Stars */
.stars {
position: absolute;
width: 100%;
height: 100%;
top: 100%;
left: 0;
transition: 0.5s;
background-image:
radial-gradient(1px 1px at 20px 30px, white, transparent),
radial-gradient(1px 1px at 50px 10px, white, transparent),
radial-gradient(2px 2px at 80px 50px, white, transparent),
radial-gradient(1px 1px at 110px 20px, white, transparent);
z-index: 4;
}
/* Dark Mode Activations */
input:checked + .slider { background-color: var(--night-sky); }
input:checked + .slider .handle {
transform: translateX(68px);
background-color: #e2e8f0;
box-shadow: 0 0 15px rgba(255,255,255,0.4);
}
input:checked + .slider .stars { top: 0; }
input:checked + .slider .cloud { opacity: 0; transform: translateY(-20px); }
.label-text {
margin-top: 25px;
font-size: 1.1rem;
font-weight: 600;
}
footer {
margin-top: 40px;
font-size: 0.9rem;
}
footer a {
color: var(--focus-glow);
text-decoration: none;
transition: color 0.3s;
}
footer a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="window-container">
<label class="switch">
<input type="checkbox"
id="mode-toggle"
aria-label="Currently Light Mode - Switch to Dark Mode"
role="button">
<span class="slider">
<span class="panes" aria-hidden="true"></span>
<span class="cloud c1" aria-hidden="true"></span>
<span class="cloud c2" aria-hidden="true"></span>
<span class="stars" aria-hidden="true"></span>
<span class="handle" aria-hidden="true"></span>
</span>
</label>
<div class="label-text">
Current Theme: <span id="mode-status">Light Mode</span>
</div>
<footer>
<a href="http://robertjmccaffery.com/examples.html">Back to Examples</a> |
<a href="http://robertjmccaffery.com/">Home</a>
</footer>
</div>
<script>
const toggle = document.getElementById('mode-toggle');
const body = document.body;
const status = document.getElementById('mode-status');
toggle.addEventListener('change', () => {
const isDark = toggle.checked;
// Update the visual theme
body.classList.toggle('dark-mode', isDark);
// Update the label to describe the NEXT action
// If it's currently dark, the button should say "Switch to Light Mode"
const nextMode = isDark ? "Currently Dark Mode - Switch to Light Mode" : "Currently Light Mode - Switch to Dark Mode";
toggle.setAttribute('aria-label', nextMode);
// Update the visual status text
status.textContent = isDark ? "Dark Mode" : "Light Mode";
});
</script>
</body>
</html>