-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcarousel.js
34 lines (28 loc) · 834 Bytes
/
carousel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const carouselContent = document.querySelectorAll(".carousel-item");
let activeIndex = 0;
function updateCarousel() {
for (let i = 0; i < carouselContent.length; i++) {
carouselContent[i].classList.remove("active");
}
carouselContent[activeIndex].classList.add("active");
}
function cycleCarousel() {
activeIndex++;
if (activeIndex >= carouselContent.length) {
activeIndex = 0;
}
updateCarousel();
}
updateCarousel();
setInterval(cycleCarousel, 6000);
// toggle menu bar
document.addEventListener("DOMContentLoaded", function() {
let menuBar = document.querySelector(".menu-bar");
window.addEventListener("scroll", function() {
if (window.scrollY > 0) {
menuBar.classList.add("scrolled");
} else {
menuBar.classList.remove("scrolled");
}
});
});