Files
olimparena/assets/js/main.js
2026-04-23 18:01:48 +03:00

59 lines
1.6 KiB
JavaScript

(() => {
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const selectors = [
".section__head",
".info-card",
".feature-card",
".object-card",
".service-card",
".gallery__item",
".review-card",
".stats article",
".booking__form",
".contacts-card",
".hours-card",
".footer__col",
".footer__bottom"
];
const elements = Array.from(document.querySelectorAll(selectors.join(",")));
if (!elements.length) return;
const siblingCounters = new WeakMap();
elements.forEach((element) => {
element.classList.add("scroll-reveal");
const parent = element.parentElement;
let offsetIndex = 0;
if (parent) {
offsetIndex = siblingCounters.get(parent) ?? 0;
siblingCounters.set(parent, offsetIndex + 1);
}
element.style.setProperty("--reveal-delay", `${(offsetIndex % 4) * 80}ms`);
});
if (reduceMotion || !("IntersectionObserver" in window)) {
elements.forEach((element) => element.classList.add("is-visible"));
return;
}
const observer = new IntersectionObserver(
(entries, currentObserver) => {
entries.forEach((entry) => {
if (!entry.isIntersecting) return;
entry.target.classList.add("is-visible");
currentObserver.unobserve(entry.target);
});
},
{
threshold: 0.18,
rootMargin: "0px 0px -12% 0px"
}
);
elements.forEach((element) => observer.observe(element));
})();