-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
97 lines (80 loc) · 2.41 KB
/
index.html
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="style.css"
<title></title>
</head>
<body>
<div class="wrap">
<!-- onClick Arrows -->
<div id="arrow-left" class="arrow"></div>
<div id="arrow-right" class="arrow"></div>
<div id="slider">
<!-- Imagae gallary -->
<div class="slide slide1">
<div class="slider-content">
<span>Image One</span>
</div>
</div>
<div class="slide slide2">
<div class="slider-content">
<span>Image Two</span>
</div>
</div>
<div class="slide slide3">
<div class="slider-content">
<span>Image Three</span>
</div>
</div>
</div>
</div>
<!-- JavaScript -->
<script>
let sliderImage = document.querySelectorAll('.slide'),
arrowLeft = document.querySelector('#arrow-left'),
arrowRight = document.querySelector('#arrow-right'),
current = 0;
//This will clear all images
function reset() {
for(let i =0; i < sliderImage.length; i++){
sliderImage[i].style.display = 'none';
}
}
//This init the slider
function startSlide() {
reset();
sliderImage[0].style.display = 'block';
}
//Show previous slide
function slideLeft() {
reset();
sliderImage[current - 1].style.display = 'block';
current--;
}
//Show next image
function slideRight(){
reset();
sliderImage[current +1].style.display = 'block';
current++;
}
//Left arrow click
arrowLeft.addEventListener('click', function(){
if(current === 0){
current = sliderImage.length;
}
slideLeft();
});
//Right arrow click
arrowRight.addEventListener('click', function(){
if(current === sliderImage.length -1){
current = -1;
}
slideRight();
});
startSlide();
</script>
</body>
</html>