-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimpleSlider.js
37 lines (35 loc) · 1.02 KB
/
simpleSlider.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
/* Setting the default slide start index: */
let slideIndex = 1;
/* We call the function that is implemented below: */
showSlides(slideIndex);
/* Increase the index by 1 - show the next slide: */
function nextSlide() {
showSlides(slideIndex += 1);
}
/* Decrease the index by 1 - show the previous slide: */
function previousSlide() {
showSlides(slideIndex -= 1);
}
/* Set the current slide: */
function currentSlide(n) {
showSlides(slideIndex = n);
}
/* Flip function: */
function showSlides(n) {
let i;
/* We refer to the elements with the class name "item", that is, to the pictures: */
let slides = document.getElementsByClassName("item");
/* Checking the number of slides: */
if (n > slides.length) {
slideIndex = 1
}
if (n < 1) {
slideIndex = slides.length
}
/* Loop through each slide in a for loop: */
for (let slide of slides) {
slide.style.display = "none";
}
/* Making an element block: */
slides[slideIndex - 1].style.display = "block";
}