-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
47 lines (40 loc) · 962 Bytes
/
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
var sliderImages = document.querySelectorAll('.slide'),
arrowLeft = document.querySelector('#arrow-left'),
arrowRight = document.querySelector('#arrow-right'),
current = 0;
// clear all images
function reset(){
for(let i=0; i< sliderImages.length; i++){
sliderImages[i].style.display = 'none';
}
}
// init slider
function startSlide(){
reset();
sliderImages[0].style.display = 'block';
}
// show prev
function slideLeft(){
reset();
sliderImages[current-1].style.display = 'block';
current--;
}
// show next
function slideRight(){
reset();
sliderImages[current+1].style.display = 'block';
current++;
}
arrowLeft.addEventListener('click', function(){
if (current === 0){
current = sliderImages.length;
}
slideLeft();
});
arrowRight.addEventListener('click', function(){
if (current === sliderImages.length-1){
current = -1;
}
slideRight();
});
startSlide();