-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
48 lines (39 loc) · 1.3 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
41
42
43
44
45
46
47
48
//BURGERMENU TOGGLE
const toggleButton = document.getElementsByClassName("mobile-nav-toggle")[0];
const navbarLinks = document.getElementsByClassName("navigation-list")[0];
toggleButton.addEventListener("click", () => {
navbarLinks.classList.toggle("active");
});
//DARKMODE
// check for saved 'darkMode' in localStorage
let darkMode = localStorage.getItem("darkMode");
const darkModeToggle = document.querySelector("#dark-mode-toggle");
const enableDarkMode = () => {
// 1. Add the class to the body
document.body.classList.add("darkmode");
// 2. Update darkMode in localStorage
localStorage.setItem("darkMode", "enabled");
};
const disableDarkMode = () => {
// 1. Remove the class from the body
document.body.classList.remove("darkmode");
// 2. Update darkMode in localStorage
localStorage.setItem("darkMode", null);
};
// If the user already visited and enabled darkMode
// start things off with it on
if (darkMode === "enabled") {
enableDarkMode();
}
// When someone clicks the button
darkModeToggle.addEventListener("click", () => {
// get their darkMode setting
darkMode = localStorage.getItem("darkMode");
// if it not current enabled, enable it
if (darkMode !== "enabled") {
enableDarkMode();
// if it has been enabled, turn it off
} else {
disableDarkMode();
}
});