-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.js
24 lines (19 loc) · 891 Bytes
/
list.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
document.addEventListener("DOMContentLoaded", function() {
const carousel = document.querySelector(".carousel");
const imagesContainer = document.querySelector(".carousel-images");
const prevBtn = document.querySelector(".prev");
const nextBtn = document.querySelector(".next");
const imageWidth = carousel.clientWidth;
let currentIndex = 0;
function showImage(index) {
imagesContainer.style.transform = `translateX(-${index * imageWidth}px)`;
}
nextBtn.addEventListener("click", function() {
currentIndex = (currentIndex + 1) % imagesContainer.children.length;
showImage(currentIndex);
});
prevBtn.addEventListener("click", function() {
currentIndex = (currentIndex - 1 + imagesContainer.children.length) % imagesContainer.children.length;
showImage(currentIndex);
});
});