feat: added new blocks/form changed
This commit is contained in:
@@ -55,6 +55,73 @@
|
||||
elements.forEach((element) => observer.observe(element));
|
||||
})();
|
||||
|
||||
(() => {
|
||||
const counters = Array.from(document.querySelectorAll(".js-counter"));
|
||||
if (!counters.length) return;
|
||||
|
||||
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
||||
|
||||
const formatCounter = (counter, value) => {
|
||||
const suffix = counter.dataset.suffix || "";
|
||||
counter.textContent = `${value}${suffix}`;
|
||||
};
|
||||
|
||||
const setFinalValue = (counter) => {
|
||||
const target = Number(counter.dataset.target || 0);
|
||||
formatCounter(counter, Number.isFinite(target) ? target : 0);
|
||||
};
|
||||
|
||||
const animateCounter = (counter) => {
|
||||
const target = Number(counter.dataset.target || 0);
|
||||
const duration = Number(counter.dataset.duration || 1300);
|
||||
|
||||
if (!Number.isFinite(target) || target <= 0) {
|
||||
setFinalValue(counter);
|
||||
return;
|
||||
}
|
||||
|
||||
let startTime = null;
|
||||
|
||||
const tick = (timestamp) => {
|
||||
if (startTime === null) startTime = timestamp;
|
||||
|
||||
const progress = Math.min((timestamp - startTime) / duration, 1);
|
||||
const currentValue = Math.floor(progress * target);
|
||||
formatCounter(counter, currentValue);
|
||||
|
||||
if (progress < 1) {
|
||||
window.requestAnimationFrame(tick);
|
||||
return;
|
||||
}
|
||||
|
||||
setFinalValue(counter);
|
||||
};
|
||||
|
||||
window.requestAnimationFrame(tick);
|
||||
};
|
||||
|
||||
if (reduceMotion || !("IntersectionObserver" in window)) {
|
||||
counters.forEach(setFinalValue);
|
||||
return;
|
||||
}
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
(entries, currentObserver) => {
|
||||
entries.forEach((entry) => {
|
||||
if (!entry.isIntersecting) return;
|
||||
animateCounter(entry.target);
|
||||
currentObserver.unobserve(entry.target);
|
||||
});
|
||||
},
|
||||
{ threshold: 0.45 }
|
||||
);
|
||||
|
||||
counters.forEach((counter) => {
|
||||
formatCounter(counter, 0);
|
||||
observer.observe(counter);
|
||||
});
|
||||
})();
|
||||
|
||||
(() => {
|
||||
const bookingForm = document.getElementById("booking-form");
|
||||
const successModal = document.getElementById("booking-success-modal");
|
||||
|
||||
Reference in New Issue
Block a user