From 3061dca553b8fc2c2a586acba243d02c35a4e617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=91=D0=B0=D0=BD=D0=B4?= =?UTF-8?q?=D1=83=D1=80=D0=B8=D1=81=D1=82?= Date: Thu, 22 Oct 2026 17:19:15 +1000 Subject: [PATCH] refactor: simplify specialty cards and remove redundant CSS --- assets/css/media.css | 36 -------- assets/css/style.css | 129 +++++++++++++++------------- components/SpecialtyCard.vue | 15 ++-- composables/useProductCardReveal.ts | 52 +++++++++++ pages/index.vue | 1 + 5 files changed, 129 insertions(+), 104 deletions(-) create mode 100644 composables/useProductCardReveal.ts diff --git a/assets/css/media.css b/assets/css/media.css index 1202fc0..3b7e84f 100644 --- a/assets/css/media.css +++ b/assets/css/media.css @@ -4,21 +4,12 @@ align-items: center; } - .product-card:hover .card-info { - top: 35%; - } .sticky-block { width: 25px; padding: 20px 0; } } -@media (min-width: 600px) and (max-width: 710px) { - .product-card:hover .card-info { - transform: translateY(-80%); - } -} - @media (max-width: 768px) { .sticky-block { width: 30px; @@ -178,17 +169,6 @@ white-space: normal; font-size: 1.4rem; } - - /* Кнопки в карточках */ - .btn-card { - width: 100%; - margin-top: 10px; - font-size: 0.9rem; - } - - .product-card .card-text { - max-height: 100px; - } } @media (min-width: 700px) and (max-width: 991px) { @@ -216,12 +196,6 @@ } } -@media (min-width: 1400px) and (max-width: 1660px) { - .product-card:hover .card-info { - top: 29%; - } -} - @media (max-width: 420px) { /* Уменьшаем размер кнопок на очень маленьких экранах */ .cta-btn { @@ -241,14 +215,4 @@ h2 { font-size: 1.3rem; } - - /* Карточки специальностей на маленьких экранах */ - .btn-card { - font-size: 0.85rem; - padding: 6px 15px; - } - - .product-card .card-text { - max-height: 80px; - } } diff --git a/assets/css/style.css b/assets/css/style.css index 8bf4d7b..717a230 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -98,14 +98,19 @@ p.pt-3.text-color { color: #328639; } -/* Карточки специальностей */ +/* Карточки специальностей: картинка задаёт высоту карточки (как было раньше), + заголовок поверх неё, полное описание раскрывается при наведении. + Карточка — ссылка целиком. */ .product-card { position: relative; + display: block; overflow: hidden; border-radius: 10px; - transition: transform 0.3s ease-in-out; + color: inherit; + text-decoration: none; } +/* Затемнение появляется только при наведении или активации (мобильные). */ .product-card::before { content: ""; position: absolute; @@ -115,92 +120,96 @@ p.pt-3.text-color { bottom: 0; background-color: transparent; transition: background-color 0.3s ease-in-out; - cursor: pointer; + z-index: 1; } -.product-card:hover::before { +.product-card:hover::before, +.product-card:focus-visible::before, +.product-card--active::before { background-color: rgba(0, 0, 0, 0.6); } +.product-card:focus-visible { + outline: 3px solid #28a745; + outline-offset: 2px; +} + +/* Изображение в потоке: высота карточки равна высоте фото, ничего не обрезается. */ .product-card img { width: 100%; height: auto; display: block; } -.card-info { +/* Текстовый слой занимает всю карточку и центрирован флексом: + одинаково на любом разрешении, без перестроений в медиа-запросах. */ +.product-card .card-info { position: absolute; - bottom: 0; + top: 0; left: 0; right: 0; - background-color: transparent; + bottom: 0; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; color: white; - padding: 1rem; text-align: center; - z-index: 1; - transition: all 0.3s ease-in-out; + padding: 1rem; + z-index: 2; + overflow: hidden; } -.product-card:hover .card-info { - top: 50%; - transform: translateY(-50%); - cursor: pointer; +/* В свёрнутом состоянии заголовок стоит ровно по центру, отступ + появляется вместе с описанием — блок остаётся центрированным. */ +.product-card .card-title { + margin-bottom: 0; + transition: margin-bottom 0.35s ease-in-out; } -.card-title { +.product-card:hover .card-title, +.product-card:focus-visible .card-title, +.product-card--active .card-title { margin-bottom: 0.5em; } +/* Описание разворачивается на месте (grid-строки 0fr -> 1fr): текст + остаётся строго внутри карточки, без прокрутки и переполнения. */ +.product-card .card-text-wrap { + display: grid; + grid-template-rows: 0fr; + transition: grid-template-rows 0.35s ease-in-out; +} + +.product-card:hover .card-text-wrap, +.product-card:focus-visible .card-text-wrap, +.product-card--active .card-text-wrap { + grid-template-rows: 1fr; +} + .product-card .card-text { - display: none; - transition: opacity 0.3s ease-in-out; - overflow-y: auto; - max-height: 100px; - margin-bottom: 10px; + overflow: hidden; + min-height: 0; + margin: 0; + opacity: 0; + transform: translateY(8px); + transition: + opacity 0.3s ease-in-out, + transform 0.3s ease-in-out; + font-size: clamp(0.75rem, 1.5vw, 0.95rem); + line-height: 1.45; } -.product-card:hover .card-text { - display: block; +.product-card:hover .card-text, +.product-card:focus-visible .card-text, +.product-card--active .card-text { + opacity: 1; + transform: translateY(0); } -/* Скроллбар для текста в карточках специальностей */ -.product-card .card-text::-webkit-scrollbar { - width: 4px; -} - -.product-card .card-text::-webkit-scrollbar-track { - background: rgba(255, 255, 255, 0.1); - border-radius: 2px; -} - -.product-card .card-text::-webkit-scrollbar-thumb { - background: #28a745; - border-radius: 2px; -} - -.product-card .card-text::-webkit-scrollbar-thumb:hover { - background: #218838; -} - -/* Кнопки в карточках специальностей */ -.btn-card { - display: inline-block; - margin-top: 12px; - padding: 8px 20px; - background-color: #28a745; - color: white; - text-decoration: none; - border-radius: 5px; - font-size: 0.9rem; - font-weight: 600; - transition: all 0.3s ease; - border: 2px solid #28a745; -} - -.btn-card:hover { - background-color: transparent; - color: #28a745; - transform: translateY(-2px); +/* Отступ заголовка для карточек преимуществ (BenefitCard). */ +.card-title { + margin-bottom: 0.5em; } /* Видео */ diff --git a/components/SpecialtyCard.vue b/components/SpecialtyCard.vue index 85d411d..4b05da1 100644 --- a/components/SpecialtyCard.vue +++ b/components/SpecialtyCard.vue @@ -7,23 +7,22 @@ defineProps<{ specialty: Specialty }>(); diff --git a/composables/useProductCardReveal.ts b/composables/useProductCardReveal.ts new file mode 100644 index 0000000..7323b34 --- /dev/null +++ b/composables/useProductCardReveal.ts @@ -0,0 +1,52 @@ +/** + * Анимация раскрытия текста в карточках специальностей (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; + }); +} diff --git a/pages/index.vue b/pages/index.vue index d535a65..bef2711 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -55,6 +55,7 @@ useHead({ }); useReveal(); +useProductCardReveal(); const phoneHref = CONTACTS.phones[0].href;