-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
54 lines (44 loc) · 1.15 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
49
50
51
52
53
54
let images = null;
let descriptions = null;
let classImage = ".image";
let classDesc = ".desc";
let currentObj = 0;
let newObj = 0;
let size = 0;
let transitionLeft = "left";
let transitionRight = "right";
let animate = "transition";
let start = "Start";
let end = "End";
function transition() {
images.forEach((image, indx) => {
image.style.transform = `translateX(${100 * (indx - currentObj)}%)`;
});
descriptions.forEach((desc, indx) => {
desc.style.transform = `translateX(${100 * (indx - currentObj)}%)`;
});
}
function move(direction) {
if (direction == transitionLeft) {
currentObj--;
if (currentObj < 0) {
currentObj = size - 1;
}
} else if (direction == transitionRight) {
currentObj++;
if (currentObj >= size) {
currentObj = 0;
}
} else {
console.log("Wrong direction parameter. Carousel won't move.");
return;
}
transition();
}
function init() {
images = document.querySelectorAll(classImage);
descriptions = document.querySelectorAll(classDesc);
size = images.length;
currentObj = 0;
transition();
}