-
Notifications
You must be signed in to change notification settings - Fork 0
/
style-switcher.js
51 lines (44 loc) · 1.41 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
45
46
47
48
49
50
51
// Toggle Style Switcher
const styleSwitcherToggle = document.querySelector(".style-switcher-toggler");
styleSwitcherToggle.addEventListener("click", () => {
document.querySelector(".style-switcher").classList.toggle("open");
})
// Hide Style Switcher on scrolling
window.addEventListener("scroll", () => {
if(document.querySelector(".style-switcher").classList.contains("open"))
{
if(document.querySelector(".style-switcher").classList.remove("open"));
}
})
// Theme colours
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");
}
})
}
// 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");
}
})