-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
45 lines (39 loc) · 1.65 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
let dropdown = document.getElementById('dropdown');
let dropdownLink = document.getElementById('dropdown-link');
const subDropdown = document.getElementById('sub-dropdown');
const subDropdownList = document.querySelector(".sub-dropdown-list");
dropdownLink.addEventListener('click', () => {
const icon = document.querySelector('.drop-icon ion-icon');
icon.classList.toggle('rotate-dropicon');
dropdown.classList.toggle('open');
});
subDropdown.addEventListener('click', () => {
const icon = document.querySelector('#sub-dropdown ion-icon');
icon.classList.toggle('rotate-dropicon');
subDropdownList.classList.toggle('open');
});
const rootElement = document.documentElement;
const toggleSwitch = document.getElementById('theme');
const themeIcon = document.querySelector('#theme ion-icon');
const currentTheme = localStorage.getItem("theme");
if (currentTheme) {
rootElement.setAttribute("data-theme", currentTheme);
if (currentTheme === "dark") {
themeIcon.classList.add("bi-brightness-high")
themeIcon.classList.remove("bi-moon-stars")
}
}
function switchTheme(e) {
if (rootElement.getAttribute("data-theme") === "light") {
rootElement.setAttribute("data-theme", "dark");
themeIcon.classList.add("bi-brightness-high")
themeIcon.classList.remove("bi-moon-stars")
localStorage.setItem("theme", "dark");
} else {
rootElement.setAttribute("data-theme", "light");
themeIcon.classList.remove("bi-brightness-high")
themeIcon.classList.add("bi-moon-stars")
localStorage.setItem("theme", "light");
}
}
toggleSwitch.addEventListener("click", switchTheme, false);