-
Notifications
You must be signed in to change notification settings - Fork 2
/
style-switcher.js
44 lines (44 loc) · 1.49 KB
/
style-switcher.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
/* ================= toggle style switcher ============== */
const styleSwitcherToggle = document.querySelector(".style-switcher-toggler");
styleSwitcherToggle.addEventListener("click", () => {
document.querySelector(".style-switcher").classList.toggle("open");
})
// hide-style - switcher on scroll
window.addEventListener("scroll", () => {
if(document.querySelector(".style-switcher").classList.contains("open"))
{
document.querySelector(".style-switcher").classList.remove("open");
}
})
/* ============== theme Color ========== */
const alternateStyles = document.querySelectorAll(".alternate-style");
function setActiveStyle(color)
{
alternateStyles.forEach((style) => {
if(color === style.getAttribute("title"))
{
style.removeAttribute("disabled");
}
else
{
style.setAttribute("disabled","true");
}
})
}
/* ============== theme light and Dark mode ========== */
const dayNight = document.querySelector(".day-night");
dayNight.addEventListener("click", () => {
dayNight.querySelector("i").classList.toggle("fa-sun");
dayNight.querySelector("i").classList.toggle("fa-moon");
document.body.classList.toggle("dark");
})
window.addEventListener("load", () => {
if(document.body.classList.contains("dark"))
{
dayNight.querySelector("i").classList.add("fa-sun");
}
else
{
dayNight.querySelector("i").classList.add("fa-moon");
}
})