-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcarousel.js
68 lines (58 loc) · 1.35 KB
/
carousel.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
var image = document.getElementById('image');
var imgList = document.getElementsByTagName('img');
var imgArray = [];
var tracker;
var timer;
for (i = 0; i < imgList.length; i+=1) {
imgArray.push(imgList[i].src);
}
function fadeIn() {
if (image.style.opacity >= 1) {
return;
}
image.style.opacity = parseFloat(image.style.opacity, 10) + 0.01;
}
// function fadeOut() {
// if (image.style.opacity <= 0) {
// return;
// }
// image.style.opacity -= 0.01;
// }
function next() {
image.style.opacity = 0;
for( i = 0; i < imgArray.length; i += 1) {
if(image.src === imgArray[i]) {
if (image.src === imgArray[imgArray.length - 1]) {
tracker = imgArray[0];
} else {
tracker = imgArray[i + 1];
}
}
}
return (image.src = tracker);
}
function previous() {
image.style.opacity = 0;
for( i = 0; i < imgArray.length; i += 1) {
if(image.src === imgArray[i]) {
if (image.src === imgArray[0]) {
tracker = imgArray[imgArray.length - 1];
} else {
tracker = imgArray[i - 1];
}
}
}
return (image.src = tracker);
}
var nextButton = document.getElementById('next');
var previousButton = document.getElementById('previous');
nextButton.onclick = function() {
clearInterval(timer);
timer = setInterval(fadeIn, 10);
next();
}
previousButton.onclick = function() {
clearInterval(timer);
timer = setInterval(fadeIn, 10);
previous();
}