-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
50 lines (42 loc) · 1.76 KB
/
script.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
document.addEventListener('DOMContentLoaded', () => {
const carouselImages = document.querySelector('.carousel-images');
const images = document.querySelectorAll('.carousel-images img');
const prevButton = document.querySelector('button.prev');
const nextButton = document.querySelector('button.next');
const pauseButton = document.querySelector('button.pause');
const rows = document.querySelectorAll('#componentTable tbody tr');
let currentIndex = 0;
let autoPlayInterval;
let isPaused = false;
function updateCarousel() {
const offset = -currentIndex * 100;
carouselImages.style.transform = `translateX(${offset}%)`;
rows.forEach((row, index) => {
row.classList.toggle('highlight', index === currentIndex);
});
}
function showNextImage() {
currentIndex = (currentIndex + 1) % images.length;
updateCarousel();
}
function showPrevImage() {
currentIndex = (currentIndex - 1 + images.length) % images.length;
updateCarousel();
}
function toggleAutoPlay() {
if (isPaused) {
autoPlayInterval = setInterval(showNextImage, 3000);
pauseButton.innerHTML = '⏸'; // Icono de pausa
} else {
clearInterval(autoPlayInterval);
pauseButton.innerHTML = '▶️'; // Icono de play
}
isPaused = !isPaused;
}
prevButton.addEventListener('click', showPrevImage);
nextButton.addEventListener('click', showNextImage);
pauseButton.addEventListener('click', toggleAutoPlay);
// Auto-play functionality
autoPlayInterval = setInterval(showNextImage, 3000); // Cambia la imagen cada 3 segundos
updateCarousel();
});