-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs_slider_css.html
166 lines (149 loc) · 5.3 KB
/
js_slider_css.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Slider immagini</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0" />
<link href="https://fonts.googleapis.com/css2?family=Jersey+10&family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=Raleway:ital,wght@0,787;1,787&display=swap" rel="stylesheet">
<style>
*{
box-sizing: border-box;
margin: 0;
padding: 0;
}
header{
width: 100%;
background-color: #F2C230;
}
h3{
font-family: "Poppins", sans-serif;
font-weight: 700;
font-style: normal;
font-size: 43px;
}
p{
font-family: "Poppins", sans-serif;
font-weight: 400;
font-style: normal;
color: white;
}
header img{
width: 4%;
height: 4%;
padding: 10px;
}
body{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background-image: url(immagini/imagine1.jpg);
}
.slider-img{
width: 50%;
background-color: #D7D9D2;
height: 460px;
padding: 10px;
margin: 6%;
box-shadow: 0px 10px 20px 1px black;
}
.btn{
position: absolute;
padding: 10px;
height: 130px;
background-color: rgba(131, 131, 131, 0.712);
color: white;
border: none;
cursor: pointer;
}
.btn:active{
background-color: rgba(207, 207, 207, 0.712);
color: rgb(56, 56, 56);
}
.btn.left{
left: 25%;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
}
.btn.right{
left: 71.79%;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
.sliders{
width: 100%;
height: 380px;
position: relative;
display: flex;
flex-direction: row;
overflow: hidden;
background-color: white;
}
.sliders img{
width: 100%;
height: auto;
position: absolute;
left: 100%;
}
.sliders img.active{
left: 0;
transition: all 0.3s ease-in-out;
}
</style>
</head>
<body>
<header>
<a href="index.html"><img src="immagini/icon/js_blank.svg" alt="logo"></a>
</header>
<div class="slider-img">
<div class="sliders" id="sliders">
<img src="immagini/thumb1.png" alt="alt" class="active">
<img src="immagini/thumb2.jpeg" alt="alt">
<img src="immagini/thumb3.jpg" alt="alt">
<img src="immagini/tigre-2-scaled.jpg" alt="alt">
</div>
</div>
<button class="btn left" id="left"><span class="material-symbols-outlined">chevron_left</span></button>
<button class="btn right" id="right"><span class="material-symbols-outlined">chevron_right</span></button>
<script>
var sliders = document.getElementById('sliders');
var imgs = sliders.getElementsByTagName('img');
var btn_right = document.getElementById('right');
var btn_left = document.getElementById('left');
var currentSlide = 0;
function Src_Img(){
//la funzione prende tutte immagini rimuovendo la classe active impostando lo stile a -100%
//Controlla se il contatore è tra lo zero e l'ultima immagine
if(currentSlide >= 0 && currentSlide < imgs.length){
for (var i = 0; i < imgs.length; i++) {
imgs[i].removeAttribute('class');
imgs[i].style.left = '100%';
}
//la lista di immagini impostata dalla variabile indice aggiunge la classe e stile quando viene mostrato un immaggine
imgs[currentSlide].setAttribute('class', 'active');
imgs[currentSlide].style.left = '0';
}
}
btn_right.addEventListener('click', function(){
currentSlide++;
//limite impone che l'ultima immagine sia maggiore del totale si ritorna all'inizio.
if (currentSlide > imgs.length-1) {
currentSlide = 0;
}
Src_Img();
})
btn_left.addEventListener('click', function(){
currentSlide--;
//limite impone che quando si raggiunge il limite che quando il contatore e minore di zero si ritorna all'ultima immagine.
if (currentSlide < 0) {
currentSlide = imgs.length-1;
}
Src_Img();
})
</script>
</body>
</html>