-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
30 lines (25 loc) · 866 Bytes
/
script.js
File metadata and controls
30 lines (25 loc) · 866 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
29
30
let numberOfSlides = document.querySelectorAll('.slider section').length;
const right = document.querySelector('.right');
const left = document.querySelector('.left');
const slider = document.querySelector('.slider');
let sectionIndex = 0;
function resetSlider() {
Array.from(slider.children).forEach((section) => {
section.style.opacity = 0;
section.style.zIndex = 0;
});
}
function showSlide(index) {
slider.children[index].style.opacity = 1;
slider.children[index].style.zIndex = 1;
}
right.addEventListener('click', () => {
resetSlider();
sectionIndex = (sectionIndex < numberOfSlides - 1) ? sectionIndex + 1 : 0;
showSlide(sectionIndex);
});
left.addEventListener('click', () => {
resetSlider();
sectionIndex = (sectionIndex > 0) ? sectionIndex - 1 : numberOfSlides - 1;
showSlide(sectionIndex);
});