-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
32 lines (28 loc) · 1.15 KB
/
main.js
File metadata and controls
32 lines (28 loc) · 1.15 KB
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
const rootElement = document.documentElement;
const toggleSwitch = document.getElementById('theme');
const themeIcon = document.querySelector('#theme i');
const currentTheme = localStorage.getItem("theme");
const demoBtn = document.querySelector('.live-demo');
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")
demoBtn.classList.add('bg-gradient')
localStorage.setItem("theme", "dark");
} else {
rootElement.setAttribute("data-theme", "light");
themeIcon.classList.remove("bi-brightness-high")
themeIcon.classList.add("bi-moon-stars")
demoBtn.classList.remove('bg-gradient')
localStorage.setItem("theme", "light");
}
}
toggleSwitch.addEventListener("click", switchTheme, false);