56 lines
1.6 KiB
JavaScript
56 lines
1.6 KiB
JavaScript
let currentIndex = 0;
|
|
let slides = document.getElementsByClassName("carousel-item");
|
|
let totalSlides = slides.length;
|
|
let slideInterval;
|
|
|
|
function showSlides() {
|
|
for (let i = 0; i < totalSlides; i++) {
|
|
slides[i].classList.remove("active");
|
|
}
|
|
currentIndex++;
|
|
if (currentIndex >= totalSlides) {
|
|
currentIndex = 0;
|
|
}
|
|
slides[currentIndex].classList.add("active");
|
|
}
|
|
|
|
// Set interval for automatic slide transition
|
|
slideInterval = setInterval(showSlides, 3000);
|
|
|
|
function moveSlides(n) {
|
|
clearInterval(slideInterval); // Stop automatic slide when manually navigating
|
|
currentIndex += n;
|
|
if (currentIndex >= totalSlides) {
|
|
currentIndex = 0;
|
|
} else if (currentIndex < 0) {
|
|
currentIndex = totalSlides - 1;
|
|
}
|
|
for (let i = 0; i < totalSlides; i++) {
|
|
slides[i].classList.remove("active");
|
|
}
|
|
slides[currentIndex].classList.add("active");
|
|
slideInterval = setInterval(showSlides, 3000); // Restart automatic slideshow
|
|
}
|
|
|
|
// Start the slideshow on page load
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
showSlides(); // Show the first slide
|
|
});
|
|
|
|
function toggleMenu() {
|
|
var topnav = document.getElementById("myTopnav");
|
|
topnav.classList.toggle("responsive");
|
|
}
|
|
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
var pathname = window.location.pathname;
|
|
var navLinks = document.querySelectorAll(".topnav a");
|
|
|
|
navLinks.forEach(function (link) {
|
|
if (link.getAttribute("href") === pathname.split("/").pop()) {
|
|
link.classList.add("active");
|
|
}
|
|
});
|
|
});
|
|
|
|
|