figma_adp_mobile_01

This commit is contained in:
2025-10-29 20:22:43 +03:00
parent bb1b8f4173
commit 018ee2089e
3 changed files with 628 additions and 3 deletions

112
main.js
View File

@@ -60,6 +60,60 @@ document.addEventListener('DOMContentLoaded', () => {
});
});
document.addEventListener('DOMContentLoaded', () => {
const sliderContainer = document.querySelector('.advantage_slider');
const slider = document.querySelector('.advantage_slider_items');
const slides = document.querySelectorAll('.advantage_slider_item');
let currentIndex = 0;
let dotsContainer, dots;
function initSlider() {
// если ширина > 900 — отключаем слайдер
if (window.innerWidth > 900) {
slider.style.transform = '';
if (dotsContainer) dotsContainer.remove();
return;
}
// создаём точки только если их ещё нет
if (!dotsContainer) {
dotsContainer = document.createElement('div');
dotsContainer.classList.add('slider_dots');
slides.forEach((_, i) => {
const dot = document.createElement('div');
dot.classList.add('slider_dot');
if (i === 0) dot.classList.add('active');
dot.addEventListener('click', () => moveToSlide(i));
dotsContainer.appendChild(dot);
});
sliderContainer.appendChild(dotsContainer);
dots = dotsContainer.querySelectorAll('.slider_dot');
}
moveToSlide(0); // начальная позиция
}
function moveToSlide(index) {
if (window.innerWidth > 900) return; // не сдвигать если десктоп
if (index < 0) index = slides.length - 1;
if (index >= slides.length) index = 0;
currentIndex = index;
const slideWidth = slides[0].offsetWidth + 28; // с учётом gap
slider.style.transform = `translateX(-${index * slideWidth}px)`;
updateDots();
}
function updateDots() {
if (!dots) return;
dots.forEach((dot, i) => dot.classList.toggle('active', i === currentIndex));
}
// пересоздаём слайдер при изменении ширины
window.addEventListener('resize', initSlider);
initSlider(); // запустить при загрузке
});
// ----------------------------------------------------------ВЫПАДАЮЩЕЕ-МЕНЮ--------------------------------------------------------
document.querySelector('.header_nav_link-reverse').addEventListener('click', function() {
@@ -108,4 +162,62 @@ document.addEventListener("DOMContentLoaded", () => {
toggleBtn.addEventListener("click", () => {
menu.classList.toggle("open");
});
});
// ---------------------------------------------SLIDER----------------------------------------------------
document.addEventListener('DOMContentLoaded', () => {
const servicesContainer = document.querySelector('.our-services_row');
const slider = document.querySelector('.our-services_row_items');
const slides = document.querySelectorAll('.our-services_row_item');
let currentIndex = 0;
let dotsContainer, dots;
let isActive = false;
function initServicesSlider() {
if (window.innerWidth > 900) {
slider.style.transform = '';
if (dotsContainer) {
dotsContainer.remove();
dotsContainer = null;
}
isActive = false;
return;
}
if (isActive) return;
isActive = true;
// создаём контейнер для точек
dotsContainer = document.createElement('div');
dotsContainer.classList.add('our-services_dots');
slides.forEach((_, i) => {
const dot = document.createElement('div');
dot.classList.add('our-services_dot');
if (i === 0) dot.classList.add('active');
dot.addEventListener('click', () => moveToSlide(i));
dotsContainer.appendChild(dot);
});
servicesContainer.appendChild(dotsContainer);
dots = dotsContainer.querySelectorAll('.our-services_dot');
moveToSlide(0);
}
function moveToSlide(index) {
if (window.innerWidth > 900) return;
if (index < 0) index = slides.length - 1;
if (index >= slides.length) index = 0;
currentIndex = index;
const offset = index * servicesContainer.offsetWidth;
slider.style.transform = `translateX(-${offset}px)`;
updateDots();
}
function updateDots() {
dots.forEach((dot, i) => dot.classList.toggle('active', i === currentIndex));
}
window.addEventListener('resize', initServicesSlider);
initServicesSlider();
});