-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
33 lines (27 loc) · 1000 Bytes
/
scripts.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
let header = document.querySelector("header");
let menu = document.querySelector("#menu-icon");
let navbar = document.querySelector(".navbar");
// Add the dark mode class initially
document.body.classList.add("active");
// Change the icon to sun initially to reflect the dark mode state
let darkmode = document.querySelector("#darkmode");
darkmode.classList.replace("bx-moon", "bx-sun");
window.addEventListener("scroll", () => {
header.classList.toggle("shadow", window.scrollY > 0);
});
menu.onclick = () => {
navbar.classList.toggle("active");
};
window.onscroll = () => {
navbar.classList.remove("active");
};
// Dark Mode / Light Mode
darkmode.onclick = () => {
if (darkmode.classList.contains("bx-moon")) {
darkmode.classList.replace("bx-moon", "bx-sun");
document.body.classList.add("active");
} else {
darkmode.classList.replace("bx-sun", "bx-moon");
document.body.classList.remove("active");
}
}