-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
37 lines (33 loc) · 812 Bytes
/
Copy pathscript.js
File metadata and controls
37 lines (33 loc) · 812 Bytes
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
const slide = document.querySelectorAll(".slide");
prev = document.querySelector(".prev");
next = document.querySelector(".next");
slide.forEach(function (slide, index) {
slide.style.left = `${index * 100}%`;
});
let counter = 0;
next.addEventListener("click", function () {
counter++;
// console.log(counter)
carousel();
});
prev.addEventListener("click", function () {
counter--;
// console.log(counter)
carousel();
});
setInterval(() => {
counter++;
carousel();
}, 4000);
function carousel() {
if (counter === slide.length) {
counter = 0;
}
if (counter < 0) {
counter = slide.length - 1;
}
slide.forEach(function (item) {
item.style.transform = `translateX(-${counter * 100}%)`;
// console.log((item.style.transform = `translateX(${counter * 100}%)`));
});
}