Files
front/composables/useProductCardReveal.ts
Uroboros 3061dca553
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
refactor: simplify specialty cards and remove redundant CSS
2026-10-22 17:19:15 +10:00

53 lines
1.8 KiB
TypeScript

/**
* Анимация раскрытия текста в карточках специальностей (product-card).
* На устройствах с курсором (hover) текст показывается при наведении
* средствами CSS. На сенсорных устройствах hover недоступен, поэтому
* карточка получает класс product-card--active, когда попадает в поле
* зрения: текст раскрывается автоматически при прокрутке.
*/
export function useProductCardReveal() {
if (import.meta.server) return;
let observer: IntersectionObserver | null = null;
const activateCards = () => {
document.querySelectorAll(".product-card").forEach((card) => {
card.classList.add("product-card--active");
});
};
onMounted(async () => {
await nextTick();
// На устройствах с курсором описания раскрываются по hover в CSS —
// автоматический показ не нужен.
const noHover = window.matchMedia("(hover: none)").matches;
if (!noHover) return;
if (typeof IntersectionObserver === "undefined") {
activateCards();
return;
}
observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("product-card--active");
}
});
},
{ threshold: 0.15, rootMargin: "0px 0px -80px 0px" },
);
document.querySelectorAll(".product-card").forEach((card) => {
observer?.observe(card);
});
});
onBeforeUnmount(() => {
observer?.disconnect();
observer = null;
});
}