-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
43 lines (37 loc) · 1.31 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
// Add your JavaScript code here
const imageContainer = document.querySelector('.image-container');
const images = imageContainer.querySelectorAll('img');
const imageDescription = document.querySelector('#image-description');
const pauseButton = document.querySelector('#pause-button');
const runButton = document.querySelector('#run-button');
const overlay = document.querySelector('.overlay');
let currentIndex = 0;
let intervalId = 0;
const imageDescriptions = [
'Image 1 description',
'Image 2 description',
'Image 3 description',
];
function displayNextImage() {
images[currentIndex].classList.add('hidden');
currentIndex = (currentIndex + 1) % images.length;
images[currentIndex].classList.remove('hidden');
setTimeout(() => {
imageDescription.textContent = imageDescriptions[currentIndex];
overlay.classList.add('visible');
}, 500);
overlay.classList.remove('visible');
}
function startSlideshow() {
intervalId = setInterval(displayNextImage, 3000);
pauseButton.style.display = 'inline-block';
runButton.style.display = 'none';
}
function stopSlideshow() {
clearInterval(intervalId);
pauseButton.style.display = 'none';
runButton.style.display = 'inline-block';
}
pauseButton.addEventListener('click', stopSlideshow);
runButton.addEventListener('click', startSlideshow);
startSlideshow();