-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcarrossel-netflix.js
57 lines (46 loc) · 1.46 KB
/
carrossel-netflix.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
55
56
$('.slider-principal').slick({
dots: true,
infinite: true,
speed: 300,
slidesToShow: 1,
adaptativeHeight: true,
autoplay: true,
autoplaySpeed: 3000
});
const controls = document.querySelectorAll('.arrow-control');
let currentItem = 0;
let items = document.querySelectorAll('.item');
let items2 = document.querySelectorAll('.item2');
const maxItems = items.length;
controls.forEach((control) => {
control.addEventListener("click", () => {
const isLeft = control.classList.contains("arrow-left");
if (isLeft) {
currentItem -= 1;
}else {
currentItem += 1;
}
if (currentItem >= maxItems) {
currentItem = 0;
}
if (currentItem < 0) {
currentItem = maxItems - 1;
}
items.forEach(item => item.classList.remove('current-item'));
items2.forEach(item2 => item2.classList.remove('current-item2'));
items[currentItem].scrollIntoView({
behavior: "center",
inline: "start",
block: "nearest",
behavior: "smooth",
});
items2[currentItem].scrollIntoView({
behavior: "center",
inline: "start",
block: "nearest",
behavior: "smooth",
});
items[currentItem].classList.add("current-item");
items2[currentItem].classList.add("current-item2");
});
});