-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
33 lines (32 loc) · 869 Bytes
/
app.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
"use strict";
const prevButton = document.querySelector(".prev");
const nextButton = document.querySelector(".next");
//
const images = document.querySelectorAll(".image__main");
const text = document.querySelectorAll(".test");
let counter = 0;
const maxSlide = text.length - 1;
const gotoSlide = (slid) => {
images.forEach((img, i) => {
img.style.transform = `translateX(${100 * (i - slid)}%)`;
});
text.forEach((t, i) => {
t.style.transform = `translateX(${100 * (i - slid)}%)`;
});
};
const nextSlide = () => {
if (counter == maxSlide) counter = 0;
else counter++;
gotoSlide(counter);
};
const prevSlide = () => {
if (counter <= 0) counter = maxSlide;
else counter--;
gotoSlide(counter);
};
const init = () => {
gotoSlide(0);
};
init();
nextButton.addEventListener("click", nextSlide);
prevButton.addEventListener("click", prevSlide);