figma_apd_mob_05

This commit is contained in:
2025-10-30 21:40:53 +03:00
parent 6cf7c5a251
commit 2bfae5248b
2 changed files with 111 additions and 20 deletions

97
main.js
View File

@@ -22,7 +22,12 @@ document.addEventListener('DOMContentLoaded', () => {
accordion.after(dotsContainer); accordion.after(dotsContainer);
let dots = []; let dots = [];
let isMobile = false; // флаг режима let isMobile = false;
let currentIndex = 0;
// Свайп
let startX = 0;
let endX = 0;
// === СОЗДАНИЕ ТОЧЕК === // === СОЗДАНИЕ ТОЧЕК ===
function createDots() { function createDots() {
@@ -47,15 +52,15 @@ document.addEventListener('DOMContentLoaded', () => {
}); });
dots.forEach(dot => dot.classList.remove('active')); dots.forEach(dot => dot.classList.remove('active'));
dots[index].classList.add('active'); if (dots[index]) dots[index].classList.add('active');
} }
// === АКТИВАЦИЯ СЛАЙДЕРА НА МОБИЛЬНОМ === // === АКТИВАЦИЯ СЛАЙДЕРА НА МОБИЛЬНОМ ===
function enableSlider() { function enableSlider() {
isMobile = true; isMobile = true;
items.forEach(item => item.classList.add('active')); // все раскрыты items.forEach(item => item.classList.add('active'));
createDots(); createDots();
let currentIndex = 0; currentIndex = 0;
showSlide(currentIndex); showSlide(currentIndex);
dots.forEach((dot, i) => { dots.forEach((dot, i) => {
@@ -65,6 +70,28 @@ document.addEventListener('DOMContentLoaded', () => {
}); });
}); });
// свайпы
accordion.addEventListener('touchstart', (e) => {
startX = e.touches[0].clientX;
});
accordion.addEventListener('touchmove', (e) => {
endX = e.touches[0].clientX;
});
accordion.addEventListener('touchend', () => {
if (!isMobile) return;
const diff = endX - startX;
if (Math.abs(diff) > 50) {
if (diff > 0) {
currentIndex = (currentIndex - 1 + items.length) % items.length;
} else {
currentIndex = (currentIndex + 1) % items.length;
}
showSlide(currentIndex);
}
});
dotsContainer.style.display = 'flex'; dotsContainer.style.display = 'flex';
} }
@@ -73,16 +100,13 @@ document.addEventListener('DOMContentLoaded', () => {
isMobile = false; isMobile = false;
dotsContainer.style.display = 'none'; dotsContainer.style.display = 'none';
// Убираем все active
items.forEach(item => { items.forEach(item => {
item.classList.remove('active'); item.classList.remove('active');
item.style.display = 'flex'; item.style.display = 'flex';
}); });
// Первая вкладка активна по умолчанию
if (items.length > 0) items[0].classList.add('active'); if (items.length > 0) items[0].classList.add('active');
// Поведение аккордеона
items.forEach(item => { items.forEach(item => {
item.onclick = () => { item.onclick = () => {
if (!isMobile) { if (!isMobile) {
@@ -104,7 +128,6 @@ document.addEventListener('DOMContentLoaded', () => {
} }
} }
// Инициализация
checkWidth(); checkWidth();
window.addEventListener('resize', checkWidth); window.addEventListener('resize', checkWidth);
}); });
@@ -115,11 +138,9 @@ document.addEventListener('DOMContentLoaded', () => {
cards.forEach(card => { cards.forEach(card => {
card.addEventListener('click', () => { card.addEventListener('click', () => {
// если уже активна — просто закрываем
if (card.classList.contains('active')) { if (card.classList.contains('active')) {
card.classList.remove('active'); card.classList.remove('active');
} else { } else {
// иначе закрываем все остальные и открываем текущую
cards.forEach(c => c.classList.remove('active')); cards.forEach(c => c.classList.remove('active'));
card.classList.add('active'); card.classList.add('active');
} }
@@ -135,14 +156,12 @@ document.addEventListener('DOMContentLoaded', () => {
let dotsContainer, dots; let dotsContainer, dots;
function initSlider() { function initSlider() {
// если ширина > 900 — отключаем слайдер
if (window.innerWidth > 900) { if (window.innerWidth > 900) {
slider.style.transform = ''; slider.style.transform = '';
if (dotsContainer) dotsContainer.remove(); if (dotsContainer) dotsContainer.remove();
return; return;
} }
// создаём точки только если их ещё нет
if (!dotsContainer) { if (!dotsContainer) {
dotsContainer = document.createElement('div'); dotsContainer = document.createElement('div');
dotsContainer.classList.add('slider_dots'); dotsContainer.classList.add('slider_dots');
@@ -157,15 +176,15 @@ document.addEventListener('DOMContentLoaded', () => {
dots = dotsContainer.querySelectorAll('.slider_dot'); dots = dotsContainer.querySelectorAll('.slider_dot');
} }
moveToSlide(0); // начальная позиция moveToSlide(0);
} }
function moveToSlide(index) { function moveToSlide(index) {
if (window.innerWidth > 900) return; // не сдвигать если десктоп if (window.innerWidth > 900) return;
if (index < 0) index = slides.length - 1; if (index < 0) index = slides.length - 1;
if (index >= slides.length) index = 0; if (index >= slides.length) index = 0;
currentIndex = index; currentIndex = index;
const slideWidth = slides[0].offsetWidth + 28; // с учётом gap const slideWidth = slides[0].offsetWidth + 28;
slider.style.transform = `translateX(-${index * slideWidth}px)`; slider.style.transform = `translateX(-${index * slideWidth}px)`;
updateDots(); updateDots();
} }
@@ -175,12 +194,31 @@ document.addEventListener('DOMContentLoaded', () => {
dots.forEach((dot, i) => dot.classList.toggle('active', i === currentIndex)); dots.forEach((dot, i) => dot.classList.toggle('active', i === currentIndex));
} }
// пересоздаём слайдер при изменении ширины // === свайп ===
window.addEventListener('resize', initSlider); let touchStartX = 0;
let touchEndX = 0;
initSlider(); // запустить при загрузке sliderContainer.addEventListener('touchstart', e => {
touchStartX = e.changedTouches[0].screenX;
});
sliderContainer.addEventListener('touchend', e => {
touchEndX = e.changedTouches[0].screenX;
handleSwipe();
});
function handleSwipe() {
const diff = touchEndX - touchStartX;
if (Math.abs(diff) < 50) return; // минимальная дистанция свайпа
if (diff > 0) moveToSlide(currentIndex - 1); // свайп вправо → предыдущий
else moveToSlide(currentIndex + 1); // свайп влево → следующий
}
window.addEventListener('resize', initSlider);
initSlider();
}); });
// ----------------------------------------------------------ВЫПАДАЮЩЕЕ-МЕНЮ-------------------------------------------------------- // ----------------------------------------------------------ВЫПАДАЮЩЕЕ-МЕНЮ--------------------------------------------------------
document.querySelector('.header_nav_link-reverse').addEventListener('click', function() { document.querySelector('.header_nav_link-reverse').addEventListener('click', function() {
@@ -282,9 +320,30 @@ document.addEventListener('DOMContentLoaded', () => {
} }
function updateDots() { function updateDots() {
if (!dots) return;
dots.forEach((dot, i) => dot.classList.toggle('active', i === currentIndex)); dots.forEach((dot, i) => dot.classList.toggle('active', i === currentIndex));
} }
// === свайп ===
let touchStartX = 0;
let touchEndX = 0;
slider.addEventListener('touchstart', e => {
touchStartX = e.changedTouches[0].screenX;
});
slider.addEventListener('touchend', e => {
touchEndX = e.changedTouches[0].screenX;
handleSwipe();
});
function handleSwipe() {
const diff = touchEndX - touchStartX;
if (Math.abs(diff) < 50) return; // минимальная длина свайпа
if (diff > 0) moveToSlide(currentIndex - 1); // свайп вправо → предыдущий
else moveToSlide(currentIndex + 1); // свайп влево → следующий
}
window.addEventListener('resize', initServicesSlider); window.addEventListener('resize', initServicesSlider);
initServicesSlider(); initServicesSlider();
}); });

View File

@@ -737,7 +737,7 @@ html, body, * {
width:418px; width:418px;
height:637px; height:637px;
border-radius:30px; border-radius:30px;
overflow:hidden; overflow: hidden;
cursor:pointer; cursor:pointer;
} }
/* Слой CLOSE */ /* Слой CLOSE */
@@ -2824,6 +2824,38 @@ body.lock {
.info_list_item { .info_list_item {
font-size: 8px; font-size: 8px;
} }
.footer_cont_heading {
font-size: 24px;
}
.item_index_color {
font-size: 24px;
}
.footer_cont_info {
font-size: 14px;
}
.footer_cont_text {
font-size: 14px;
}
.time_item_interval {
font-size: 12px;
}
.footer_cont_btn {
padding: 8px;
font-size: 12px;
}
.chart_cont_title {
font-size: 16px;
}
.chart_cont_text02,
.chart_cont_text02 span {
font-size: 10px;
}
.footer_chart {
padding: 20px;
}
.footer_chart_img {
right: 10px;
}
} }