-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
30 lines (23 loc) · 850 Bytes
/
app.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
const btnPrev = document.querySelector('[data-js="carousel__button--prev"]')
const btnNext = document.querySelector('[data-js="carousel__button--next"]')
const slides = document.querySelectorAll('[data-js="carousel__item"]')
const lastIndex = slides.length - 1
let currentSlide = 0
const manipulateSlides = correctSlide => {
slides.forEach(slide => {
slide.classList.remove('carousel__item--visible')
});
slides[correctSlide].classList.add('carousel__item--visible')
}
btnPrev.addEventListener('click', () => {
const correctSlide = currentSlide === 0
? currentSlide = 2
: --currentSlide
manipulateSlides(correctSlide)
})
btnNext.addEventListener('click', () => {
const correctSlide = currentSlide === lastIndex
? currentSlide = 0
: ++currentSlide
manipulateSlides(correctSlide)
})