-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
55 lines (46 loc) · 1.58 KB
/
main.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
47
48
49
50
51
52
53
54
55
document.addEventListener('DOMContentLoaded', function () {
let currentSlide = 0;
const slides = document.querySelectorAll('.slide');
const totalSlides = slides.length;
const prevButton = document.querySelector('.prev');
const nextButton = document.querySelector('.next');
// Function to show the selected slide
function showSlide(index) {
if (index >= totalSlides) {
currentSlide = 0;
} else if (index < 0) {
currentSlide = totalSlides - 1;
} else {
currentSlide = index;
}
// Remove active class from all slides
slides.forEach(slide => {
slide.classList.remove('active');
});
// Add active class to current slide
slides[currentSlide].classList.add('active');
}
// Move to the next slide
function nextSlide() {
showSlide(currentSlide + 1);
}
// Move to the previous slide
function prevSlide() {
showSlide(currentSlide - 1);
}
// Automatic slide transition
let autoSlide = setInterval(nextSlide, 10000);
// Stop automatic transition when clicking on arrows
prevButton.addEventListener('click', () => {
clearInterval(autoSlide);
prevSlide();
autoSlide = setInterval(nextSlide, 10000);
});
nextButton.addEventListener('click', () => {
clearInterval(autoSlide);
nextSlide();
autoSlide = setInterval(nextSlide, 10000);
});
// Show the first slide on load
showSlide(currentSlide);
});