-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
40 lines (33 loc) · 1.04 KB
/
script.js
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
// hide/show mobile menu
function toggleMenu() {
document.getElementById("site-nav").classList.toggle("open");
}
document.getElementById("menu-toggle").addEventListener("click", toggleMenu);
// hide newsletter component
// function hideNewsletter() {
// document.getElementById("newsletter").classList.add('closed');
// }
// document.getElementById("close-newsletter").addEventListener("click", hideNewsletter);
// switch between light/dark theme
var lightTheme;
if (typeof localStorage.lightTheme !== "undefined") {
lightTheme = JSON.parse(localStorage.lightTheme);
} else if (window.matchMedia("(prefers-color-scheme: light)").matches) {
lightTheme = true;
} else {
lightTheme = false;
}
function displayTheme() {
if (lightTheme) {
document.body.classList.add("light-theme");
} else {
document.body.classList.remove("light-theme");
}
}
function changeTheme() {
lightTheme = !lightTheme;
localStorage.lightTheme = lightTheme;
displayTheme();
}
document.getElementById("moon").addEventListener("click", changeTheme);
displayTheme();