-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
46 lines (35 loc) · 1.12 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
let slides = document.getElementsByClassName('slide');
let prevArrow = document.getElementById('prev');
let nextArrow = document.getElementById('next');
let slideCount = 0;
//==== TO SET THE DEFAULT IMAGE (INITIALLY)
slideShow(slideCount);
//==== EVENT LISTENER WHEN CLICK THE ARROW
prevArrow.addEventListener('click', function() {
controller(-1);
});
nextArrow.addEventListener('click', function() {
controller(1);
});
//==== FUNCTION TO CONTROL THE NEXT/PREV IMAGE
function controller(param) {
slideCount += param;
slideShow(slideCount);
}
//==== FUNCTION TO SHOW THE IMAGES AS PER THEIR TURN
function slideShow(count) {
// when want to see next img of last img, then it directs to 1st img
if(count==slides.length){
slideCount= count = 0;
}
// when want to see prev img of 1st img, then it directs to last img
if(count < 0){
slideCount= count = slides.length-1;
}
// hiding those images whose turn is not there
for(let elem of slides){
elem.style.display = 'none';
}
// to display that image whose turn it is
slides[count].style.display = 'block';
}