willowmecreationsV2/script.js

57 lines
1.6 KiB
JavaScript
Raw Normal View History

2024-05-26 03:59:54 +01:00
let currentIndex = 0;
let slides = document.getElementsByClassName("carousel-item");
let totalSlides = slides.length;
2024-10-12 03:30:22 +01:00
let slideInterval;
2024-05-26 03:59:54 +01:00
function showSlides() {
2024-08-09 06:21:29 +01:00
for (let i = 0; i < totalSlides; i++) {
slides[i].classList.remove("active");
}
currentIndex++;
if (currentIndex >= totalSlides) {
currentIndex = 0;
}
slides[currentIndex].classList.add("active");
2024-05-26 03:59:54 +01:00
}
2024-10-12 03:30:22 +01:00
// Set interval for automatic slide transition
slideInterval = setInterval(showSlides, 3000);
2024-05-26 03:59:54 +01:00
function moveSlides(n) {
2024-10-12 03:30:22 +01:00
clearInterval(slideInterval); // Stop automatic slide when manually navigating
2024-08-09 06:21:29 +01:00
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");
2024-10-12 03:30:22 +01:00
slideInterval = setInterval(showSlides, 3000); // Restart automatic slideshow
2024-05-26 03:59:54 +01:00
}
2024-10-12 03:30:22 +01:00
// Start the slideshow on page load
document.addEventListener("DOMContentLoaded", function () {
showSlides(); // Show the first slide
});
function toggleMenu() {
2024-10-12 03:30:22 +01:00
var topnav = document.getElementById("myTopnav");
topnav.classList.toggle("responsive");
}
document.addEventListener("DOMContentLoaded", function () {
2024-08-09 06:21:29 +01:00
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");
}
});
});