|
|
|
|
|
let currentSlide = 0; |
|
|
const carousel = document.getElementById('buildCarousel'); |
|
|
const items = carousel.querySelectorAll('.carousel-item'); |
|
|
const totalSlides = items.length; |
|
|
|
|
|
function updateCarousel() { |
|
|
|
|
|
items.forEach(item => item.classList.remove('active')); |
|
|
|
|
|
|
|
|
items[currentSlide].classList.add('active'); |
|
|
|
|
|
|
|
|
const itemWidth = 70; |
|
|
const offset = -currentSlide * itemWidth + 15; |
|
|
carousel.style.transform = `translateX(${offset}%)`; |
|
|
} |
|
|
|
|
|
function moveCarousel(direction) { |
|
|
|
|
|
currentSlide += direction; |
|
|
|
|
|
|
|
|
if (currentSlide < 0) { |
|
|
currentSlide = totalSlides - 1; |
|
|
} else if (currentSlide >= totalSlides) { |
|
|
currentSlide = 0; |
|
|
} |
|
|
|
|
|
updateCarousel(); |
|
|
} |
|
|
|
|
|
|
|
|
updateCarousel(); |
|
|
|
|
|
|
|
|
let autoplayInterval = setInterval(() => { |
|
|
moveCarousel(1); |
|
|
}, 5000); |
|
|
|
|
|
|
|
|
carousel.parentElement.addEventListener('mouseenter', () => { |
|
|
clearInterval(autoplayInterval); |
|
|
}); |
|
|
|
|
|
carousel.parentElement.addEventListener('mouseleave', () => { |
|
|
autoplayInterval = setInterval(() => { |
|
|
moveCarousel(1); |
|
|
}, 5000); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
document.querySelectorAll('a[href^="#"]').forEach(anchor => { |
|
|
anchor.addEventListener('click', function (e) { |
|
|
e.preventDefault(); |
|
|
const target = document.querySelector(this.getAttribute('href')); |
|
|
if (target) { |
|
|
target.scrollIntoView({ |
|
|
behavior: 'smooth', |
|
|
block: 'start' |
|
|
}); |
|
|
} |
|
|
}); |
|
|
}); |