-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
48 lines (41 loc) · 1.64 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
document.addEventListener("DOMContentLoaded", () => {
const items = document.querySelectorAll(".item");
const nextButton = document.querySelector(".next");
const prevButton = document.querySelector(".prev");
let currentIndex = 0;
function updateCarousel() {
items.forEach((item, index) => {
item.classList.remove("active");
if (index === currentIndex) {
item.classList.add("active");
item.style.transform = `translateZ(300px)`;
} else if (index === (currentIndex + 1) % items.length) {
item.style.transform = `translateX(300px) translateZ(100px)`;
} else if (index === (currentIndex - 1 + items.length) % items.length) {
item.style.transform = `translateX(-300px) translateZ(100px)`;
} else {
item.style.transform = `translateZ(-300px)`;
}
});
}
function moveNext() {
currentIndex = (currentIndex + 1) % items.length;
updateCarousel();
}
function movePrev() {
currentIndex = (currentIndex - 1 + items.length) % items.length;
updateCarousel();
}
nextButton.addEventListener("click", moveNext);
prevButton.addEventListener("click", movePrev);
// Adicionando clique na tela para mudar os slides
document.addEventListener("click", (event) => {
const middle = window.innerWidth / 2; // Calcula o centro da tela
if (event.clientX > middle) {
moveNext(); // Clique do lado direito
} else {
movePrev(); // Clique do lado esquerdo
}
});
updateCarousel();
});