-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
39 lines (34 loc) · 1.17 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
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
console.log(entry);
if (entry.isIntersecting) {
entry.target.classList.add("show");
} else {
entry.target.classList.remove("show");
}
});
});
const hiddenElements = document.querySelectorAll(".reason");
hiddenElements.forEach((el) => observer.observe(el));
const rootElem = document.documentElement;
const darkThemeMq = window.matchMedia("(prefers-color-scheme: dark)");
if (darkThemeMq.matches) {
rootElem.setAttribute("data-theme", "dark");
document.getElementById("switcher").src = "images/sun.svg";
} else {
rootElem.setAttribute("data-theme", "light");
document.getElementById("switcher").src = "images/moon.svg";
}
const switchTheme = () => {
let dataTheme = rootElem.getAttribute("data-theme"),
newtheme;
newTheme = dataTheme === "dark" ? "light" : "dark";
switchIcon = document.getElementById("switcher");
rootElem.setAttribute("data-theme", newTheme);
if (dataTheme === "dark") {
switcher.src = "images/moon.svg";
} else {
switcher.src = "images/sun.svg";
}
};
document.querySelector("#switcher").addEventListener("click", switchTheme);