Files
Fakel-Gym/template-parts/la-components/blocks/hero-block/hero-block.js
GP_DEV 21562852ca full
2025-07-08 14:21:19 +03:00

45 lines
1.5 KiB
JavaScript

document.addEventListener('DOMContentLoaded', function() {
const heroBlocks = document.querySelectorAll('.hero-block');
heroBlocks.forEach(function(block) {
const swiperContainer = block.querySelector('.swiper');
if (!swiperContainer) return;
const swiper = new Swiper(swiperContainer, {
slidesPerView: 1,
grabCursor: true,
on: {
slideChange: function () {
updatePagination(block, this.realIndex);
}
}
});
// Функция обновления пагинации
function updatePagination(block, activeIndex) {
const paginationItems = block.querySelectorAll('.pagination-item');
paginationItems.forEach((item, index) => {
item.setAttribute('data-active', index === activeIndex ? 'true' : 'false');
});
}
// Навигация
const prevBtn = block.querySelector('.custom-prev');
const nextBtn = block.querySelector('.custom-next');
if (prevBtn) {
prevBtn.addEventListener('click', () => swiper.slidePrev());
}
if (nextBtn) {
nextBtn.addEventListener('click', () => swiper.slideNext());
}
// Пагинация
block.querySelectorAll('.pagination-item').forEach((item, index) => {
item.addEventListener('click', () => swiper.slideToLoop(index));
});
});
});