forked from apu52/Travel_Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Theme.js
33 lines (27 loc) · 1.17 KB
/
Theme.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
// const themebtn = document.getElementById("toggle");
// themebtn.onclick = () => {
// document.body.classList.toggle("dark-theme");
// if (document.body.classList.contains("dark-theme")) {
// themebtn.innerHTML = '<i class="fa fa-sun-o" aria-hidden="true"></i>';
// console.log("Dark theme");
// } else {
// themebtn.innerHTML = '<i class="fa fa-moon-o" aria-hidden="true"></i>';
// console.log("Light theme");
// }
// };
const themeToggle = document.getElementById("themeToggle");
const themeLabel = document.querySelector(".toggle-label");
themeToggle.addEventListener("change", () => {
document.body.classList.toggle("dark-theme");
if (document.body.classList.contains("dark-theme")) {
themeLabel.style.background = "#fff"; // Adjust color for the checked state as needed
console.log("Dark theme");
document.body.classList.remove("dark-theme");
document.body.classList.add("light-theme");
} else {
themeLabel.style.background = "var(--primary-color)"; // Adjust color for the unchecked state as needed
console.log("Light theme");
document.body.classList.remove("light-theme");
document.body.classList.add("dark-theme");
}
});