-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground-slider.js
More file actions
31 lines (26 loc) · 822 Bytes
/
Copy pathbackground-slider.js
File metadata and controls
31 lines (26 loc) · 822 Bytes
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
// background-slider.js
document.addEventListener('DOMContentLoaded', () => {
const slider = document.getElementById('background-slider');
if (!slider) return;
const images = slider.querySelectorAll('img');
let currentIndex = 0;
function showImage(index) {
images.forEach((img, i) => {
if (i === index) {
img.classList.add('active');
} else {
img.classList.remove('active');
}
});
}
function nextImage() {
currentIndex = (currentIndex + 1) % images.length;
showImage(currentIndex);
}
// Afficher la première image immédiatement
if (images.length > 0) {
showImage(currentIndex);
}
// Changer d'image toutes les 5 secondes
setInterval(nextImage, 5000);
});