-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
26 lines (21 loc) · 949 Bytes
/
script.js
File metadata and controls
26 lines (21 loc) · 949 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
// script.js
const testimonials = document.querySelector(".testimonials");
const prevBtn = document.getElementById("prevBtn");
const nextBtn = document.getElementById("nextBtn");
let currentIndex = 0;
function updateSliderPosition() {
const cardWidth = document.querySelector(".testimonial-card").offsetWidth;
testimonials.style.transform = `translateX(-${currentIndex * cardWidth}px)`;
}
prevBtn.addEventListener("click", () => {
const cardCount = document.querySelectorAll(".testimonial-card").length;
currentIndex = (currentIndex - 1 + cardCount) % cardCount; // Loop back to last slide
updateSliderPosition();
});
nextBtn.addEventListener("click", () => {
const cardCount = document.querySelectorAll(".testimonial-card").length;
currentIndex = (currentIndex + 1) % cardCount; // Loop back to first slide
updateSliderPosition();
});
// Ensure the slider is responsive
window.addEventListener("resize", updateSliderPosition);