-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (25 loc) · 842 Bytes
/
script.js
File metadata and controls
28 lines (25 loc) · 842 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
<script>
document.addEventListener("DOMContentLoaded", function() {
var currentIndex = 0;
var slides = document.getElementsByClassName('carousel-item');
function showSlide(index) {
// Ensure index is within bounds
if (index >= slides.length) { index = 0; }
if (index < 0) { index = slides.length - 1; }
currentIndex = index;
// Hide all slides and remove 'active' class
for (var i = 0; i < slides.length; i++) {
slides[i].classList.remove('active');
}
// Show the selected slide
slides[currentIndex].classList.add('active');
}
// Make functions available globally
window.prevSlide = function() {
showSlide(currentIndex - 1);
}
window.nextSlide = function() {
showSlide(currentIndex + 1);
}
});
</script>