style: added adaption to mobile & block animations
This commit is contained in:
58
assets/js/main.js
Normal file
58
assets/js/main.js
Normal file
@@ -0,0 +1,58 @@
|
||||
(() => {
|
||||
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));
|
||||
})();
|
||||
Reference in New Issue
Block a user