-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
76 lines (71 loc) · 1.41 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
let models = [
{
image: "img/howen1.jpg",
},
{
image: "img/howen2.jpg",
},
{
image: "img/howen3.jpg",
},
{
image: "img/howen4.jpg",
},
];
let index = 0;
let modelCount = models.length;
let interval;
let settings = {
duration: "2000",
random: false,
};
init(settings);
document.querySelector(".fa-arrow-left").addEventListener("click", () => {
index--;
showSlide(index);
});
document.querySelector(".fa-arrow-right").addEventListener("click", () => {
index++;
showSlide(index);
});
document.querySelectorAll(".arrow").forEach((item) => {
item.addEventListener("mouseenter", () => {
clearInterval(interval);
});
});
document.querySelectorAll(".arrow").forEach((item) => {
item.addEventListener("mouseleave", () => {
init(settings);
});
});
function init(settings) {
let prev;
interval = setInterval(() => {
if (settings.random) {
do {
index = Math.floor(Math.random() * modelCount);
} while (index == prev);
prev = index;
} else {
if (modelCount == index + 1) {
index = -1;
}
showSlide(index);
index++;
}
console.log(index);
showSlide(index);
}, settings.duration);
}
function showSlide(i) {
index = i;
if (i < 0) {
index = modelCount - 1;
}
if (i >= modelCount) {
index = 0;
}
document
.querySelector(".card-img-top")
.setAttribute("src", models[index].image);
}