-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
34 lines (28 loc) · 836 Bytes
/
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
// slider carrossel: control slider
const controls = document.querySelectorAll('.control .icon-arrow');
let currentItem = 0;
const items = document.querySelectorAll('.item');
const maxItem = items.length;
controls.forEach((control) => {
control.addEventListener('click', () => {
const isLeft = control.classList.contains("arrow-left");
if(isLeft){
currentItem -=1;
}else{
currentItem +=1;
}
if(currentItem >= maxItem){
currentItem = 0;
}
if(currentItem < 0){
currentItem = maxItem - 1;
}
items.forEach((item) => item.classList.remove('current-item'));
items[currentItem].scrollIntoView({
inline: 'center',
behavior: 'smooth'
});
items[currentItem].classList.add("current-item");
console.log("control", isLeft, currentItem);
})
});