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, loop: true, 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)); }); }); });