-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
45 lines (37 loc) · 1.21 KB
/
Copy pathscripts.js
File metadata and controls
45 lines (37 loc) · 1.21 KB
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
const prevButton = document.getElementById('prev')
const nextButton = document.getElementById('next')
const items = document.querySelectorAll('.item')
const dots = document.querySelectorAll('.dot')
const numberIndicator = document.querySelector('.numbers')
const list = document.querySelector('.list')
let active = 0
const total = items.length
let timer
function update(direction) {
const activeItem = document.querySelector('.item.active')
const activeDot = document.querySelector('.dot.active')
if (activeItem) activeItem.classList.remove('active')
if (activeDot) activeDot.classList.remove('active')
if (direction > 0) {
active = active + 1
if (active === total) {
active = 0
}
} else if (direction < 0) {
active = active - 1
if (active < 0) {
active = total - 1
}
}
items[active]?.classList.add('active')
dots[active]?.classList.add('active')
if (numberIndicator) {
numberIndicator.textContent = String(active + 1).padStart(2, '0')
}
}
prevButton.addEventListener('click', () => {
update(-1)
})
nextButton.addEventListener('click', () => {
update(1)
})