-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
54 lines (49 loc) · 1.95 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
let next = document.getElementById('next');
let prev = document.getElementById('prev');
let carousel = document.querySelector('.carousel');
let items = document.querySelectorAll('.carousel .item');
let countItem = items.length;
let active = 1;
let other_1 = null;
let other_2 = null;
next.onclick = () => {
carousel.classList.remove('prev');
carousel.classList.add('next');
active =active + 1 >= countItem ? 0 : active + 1;
other_1 =active - 1 < 0 ? countItem -1 : active - 1;
other_2 = active + 1 >= countItem ? 0 : active + 1;
changeSlider();
}
prev.onclick = () => {
carousel.classList.remove('next');
carousel.classList.add('prev');
active = active - 1 < 0 ? countItem - 1 : active - 1;
other_1 = active + 1 >= countItem ? 0 : active + 1;
other_2 = other_1 + 1 >= countItem ? 0 : other_1 + 1;
changeSlider();
}
const changeSlider = () => {
let itemOldActive = document.querySelector('.carousel .item.active');
if(itemOldActive) itemOldActive.classList.remove('active');
let itemOldOther_1 = document.querySelector('.carousel .item.other_1');
if(itemOldOther_1) itemOldOther_1.classList.remove('other_1');
let itemOldOther_2 = document.querySelector('.carousel .item.other_2');
if(itemOldOther_2) itemOldOther_2.classList.remove('other_2');
items.forEach(e => {
e.querySelector('.image img').style.animation = 'none';
e.querySelector('.image figcaption').style.animation = 'none';
void e.offsetWidth;
e.querySelector('.image img').style.animation = '';
e.querySelector('.image figcaption').style.animation = '';
})
items[active].classList.add('active');
items[other_1].classList.add('other_1');
items[other_2].classList.add('other_2');
clearInterval(autoPlay);
autoPlay = setInterval(() => {
next.click();
}, 5000);
}
let autoPlay = setInterval(() => {
next.click();
}, 5000);