-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
63 lines (52 loc) · 1.7 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// SECTION TITLE & FOOTER
const sectionTitles = document.querySelectorAll(".section__title");
const sectionContainers = document.querySelectorAll(".section__container");
const sectionFooters = document.querySelectorAll(".section__footer");
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
entry.target.classList.toggle("fade", entry.isIntersecting);
if (entry.isIntersecting) observer.unobserve(entry.target);
});
},
{
threshold: 1,
}
);
sectionTitles.forEach((title) => {
observer.observe(title);
});
sectionFooters.forEach((footer) => {
observer.observe(footer);
});
// SECTION CONTAINER
const observerContainer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
entry.target.classList.toggle("left-fade", entry.isIntersecting);
if (entry.isIntersecting) observerContainer.unobserve(entry.target);
});
},
{
threshold: 0.3,
}
);
sectionContainers.forEach((container) => {
observerContainer.observe(container);
});
// THEME TOGGLE
let toggle = document.getElementById("theme-toggle");
toggle.innerHTML = `<i class="ph ph-sun"></i>`;
document.documentElement.setAttribute("data-theme", "dark");
toggle.onclick = function () {
let currentTheme = document.documentElement.getAttribute("data-theme");
if (currentTheme === "dark") {
document.documentElement.setAttribute("data-theme", "light");
toggle.classList.add("toggle-anim");
toggle.innerHTML = `<i class="ph ph-moon"></i>`;
} else if (currentTheme === "light") {
document.documentElement.setAttribute("data-theme", "dark");
toggle.classList.remove("toggle-anim");
toggle.innerHTML = `<i class="ph ph-sun"></i>`;
}
};