-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscripts_caro.js
46 lines (26 loc) · 892 Bytes
/
scripts_caro.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
34
35
36
37
38
39
40
41
42
43
44
45
46
const offreBulles = document.querySelectorAll('.offre-bulle');
const prevButton = document.querySelector('.prev-button');
const nextButton = document.querySelector('.next-button');
let activeIndex = 0;
function updateActiveBulle() {
offreBulles.forEach((bulle, index) => {
if (index === activeIndex) {
bulle.classList.add('active');
} else {
bulle.classList.remove('active');
}
});
}
function showDefaultBulle() {
activeIndex = 0;
updateActiveBulle();
}
prevButton.addEventListener('click', () => {
activeIndex = (activeIndex - 1 + offreBulles.length) % offreBulles.length;
updateActiveBulle();
});
nextButton.addEventListener('click', () => {
activeIndex = (activeIndex + 1) % offreBulles.length;
updateActiveBulle();
});
showDefaultBulle();