-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
34 lines (28 loc) · 1.01 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
let items = document.querySelectorAll('.slider .list .item');
let next = document.getElementById('next');
let prev = document.getElementById('prev');
let thumbnails = document.querySelectorAll('.thumbnail .item');
let countItem = items.length;
let itemActive = 0;
next.addEventListener('click', function() {
itemActive = (itemActive + 1) % countItem;
showSlider();
});
prev.addEventListener('click', function() {
itemActive = (itemActive - 1 + countItem) % countItem;
showSlider();
});
function showSlider() {
let itemActiveOld = document.querySelector('.slider .item.active');
let thumbnailActiveOld = document.querySelector('.thumbnail .item.active');
itemActiveOld.classList.remove('active');
thumbnailActiveOld.classList.remove('active');
items[itemActive].classList.add('active');
thumbnails[itemActive].classList.add('active');
}
thumbnails.forEach((thumbnail, index) => {
thumbnail.addEventListener('click', () => {
itemActive = index;
showSlider();
});
});