50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
const reveals = document.querySelectorAll(".reveal");
|
|
|
|
const observer =
|
|
"IntersectionObserver" in window
|
|
? new IntersectionObserver(
|
|
(entries) => {
|
|
entries.forEach((entry) => {
|
|
if (entry.isIntersecting) {
|
|
entry.target.classList.add("on");
|
|
observer.unobserve(entry.target);
|
|
}
|
|
});
|
|
},
|
|
{ threshold: 0.18 }
|
|
)
|
|
: null;
|
|
|
|
reveals.forEach((item, idx) => {
|
|
item.style.transitionDelay = `${Math.min(idx * 45, 280)}ms`;
|
|
if (observer) {
|
|
observer.observe(item);
|
|
} else {
|
|
item.classList.add("on");
|
|
}
|
|
});
|
|
|
|
const navLinks = document.querySelectorAll(".main-nav a");
|
|
|
|
if ("IntersectionObserver" in window) {
|
|
const sectionObserver = new IntersectionObserver(
|
|
(entries) => {
|
|
entries.forEach((entry) => {
|
|
if (entry.isIntersecting) {
|
|
navLinks.forEach((link) => {
|
|
link.classList.toggle("active", link.getAttribute("href") === `#${entry.target.id}`);
|
|
});
|
|
}
|
|
});
|
|
},
|
|
{ threshold: 0.55 }
|
|
);
|
|
|
|
["approach", "services", "cases", "contacts"].forEach((id) => {
|
|
const section = document.getElementById(id);
|
|
if (section) {
|
|
sectionObserver.observe(section);
|
|
}
|
|
});
|
|
}
|