-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
233 lines (211 loc) · 8.59 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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>input range</title>
<style type="text/css">
@import url('https://fonts.googleapis.com/css2?family=Assistant:wght@200&family=Raleway:ital,wght@0,300;1,200&display=swap');
body {
margin: 0;
padding: 10px 10px 10px 10px;
font-family: 'Assistant', sans-serif;
background-color: rgb(175,175,175);
}
main {
min-width: 300px;
max-width: 820px;
border-radius: 10px;
margin: auto;
background-color: #CBD3E1;
box-shadow: 1px 1px 15px rgba(0,0,0, 0.3);
}
section {
display: flex;
width: 100%;
height: 100%;
margin: auto;
background-image: linear-gradient(to top,
#50453f 5%,
#8A7862, #9A836A);
}
footer > div{
width: 50%;
max-width: 300px;
display: flex;
margin: 30px auto 10px auto;
flex-wrap: wrap;
justify-content: space-between;
}
footer > p {
text-align: center;
margin-bottom: 15px;
}
video {
position: relative;
width: 80%;
margin: auto;
}
div#controle {
display: flex;
position: relative;
margin: -1.2em auto 0 auto;
width: 80%;
opacity: 0;
transition-duration: 7s;
color: white;
background-color: rgba(0,0,0, 0.6);
box-shadow: 1px 1px 4px rgba(0,0,0, 0.3)
}
div#controle:hover {
transition-duration: 50ms;
opacity: 1;
}
span[wm-temporizador="meuVideo"] {
margin: auto 10px;
font-size: 0.8rem
}
h1 {
text-indent: 20px;
padding: 33px 20px 10px 20px;
font-size: 1.4em;
font-weight: bold;
text-decoration: underline;
text-shadow: 1px 1px 3px rgba(0,0,0, 0.4);
}
h2 {
text-indent: 20px;
padding: 10px 20px 10px 20px;
font-size: 1.3em;
font-weight: 200;
}
button {
border: none;
background: transparent;
}
input[type=range] {
-webkit-appearance:none;
appearance: none;
margin-left: 0;
background-color: rgb(190,190,190);
height: 1em;
width: 100%;
opacity: 0.6;
}
input[type=range]:hover { opacity: 1 }
input[type=range]::-webkit-slider-thumb:hover {
-webkit-appearance: none;
appearance: none;
width: 15px;
height: 15px;
background: gray;
opacity: 1;
transition-duration: 400ms;
}
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 20px;
height: 20px;
opacity: 0;
transition-duration: 400ms;
}
</style>
</head>
<body>
<main>
<h1>input range</h1>
<h2>Criação de barra de controle de vídeo com funcionalidades de play, pause e controle da barra de progresso. </h2>
<section>
<video src="video.mp4" id="meuVideo" title="Vídeo de Kelly L no Pexels" autoplay="true">
</section>
<div id="controle">
<button wm-playPause="meuVideo"><svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px"
width="15" height="15"
viewBox="0 0 172 172"
style=" fill:#000000;"><g fill="none" fill-rule="nonzero" stroke="none" stroke-width="1" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="10" stroke-dasharray="" stroke-dashoffset="0" font-family="none" font-weight="none" font-size="none" text-anchor="none" style="mix-blend-mode: normal"><path d="M0,172v-172h172v172z" fill="none"></path><g fill="#ffffff"><path d="M34.4,17.2c-3.16643,0 -5.73333,2.5669 -5.73333,5.73333c-0.00001,0.00747 -0.00001,0.01493 0,0.0224v63.04427v63.04427c-0.00001,0.00746 -0.00001,0.01493 0,0.02239c0,3.16643 2.5669,5.73333 5.73333,5.73333c1.19346,-0.00345 2.3561,-0.37925 3.32578,-1.075l0.0112,0.0112l113.71485,-62.52917c2.03773,-0.93223 3.34559,-2.96619 3.34817,-5.20703c0.00115,-2.30642 -1.37987,-4.38898 -3.50495,-5.28542l-113.55807,-62.45078h-0.0112c-0.97102,-0.69177 -2.13354,-1.06362 -3.32578,-1.0638z"></path></g></g></svg>
</button>
<span wm-temporizador="meuVideo">1:10/1:50</span>
<input type="range" wm-progresso="meuVideo"
min="0" max="100"
step="1"
value="0">
</div>
<footer>
<div>
<a href="https://github.com/ysh-rael"
target="_blank">
<img src="https://img.icons8.com/ios-glyphs/30/000000/github.png"
alt="redireciona para github">
</a>
<a href="https://www.linkedin.com/in/yshrael-pimentel-76502820b/"
target="_blank">
<img src="https://img.icons8.com/ios-glyphs/30/000000/linkedin.png"
alt="redireciona para linkedin">
</a>
<a href="https://mailto:[email protected]"
target="_blank">
<img src="https://img.icons8.com/ios-glyphs/30/000000/send-mass-email.png"
alt="me envie um email"></a>
</div>
<p>© Yshrael Pimentel</p>
</footer>
</main>
<script type="text/javascript">
function controlarVideo(id) {
const video = document.getElementById(id)
const playPause = document.querySelector(`[wm-playPause=${id}]`)
let pause = true // p_p: contador que identifica se video está pausado.
if (video.getAttribute('autoplay')) {pause = false; playPause.innerHTML = `<img src="https://img.icons8.com/external-dreamstale-lineal-dreamstale/15/000000/external-pause-music-dreamstale-lineal-dreamstale-2.png"/>`}
playPause.onclick = () => {
//altera entre play e pause no mesmo botão
if (pause) {
video.play()
playPause.innerHTML = `<img src="https://img.icons8.com/external-dreamstale-lineal-dreamstale/15/000000/external-pause-music-dreamstale-lineal-dreamstale-2.png"/>`
pause = false
} else {
video.pause()
playPause.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px"
width="15" height="15"
viewBox="0 0 172 172"
style=" fill:#000000;"><g fill="none" fill-rule="nonzero" stroke="none" stroke-width="1" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="10" stroke-dasharray="" stroke-dashoffset="0" font-family="none" font-weight="none" font-size="none" text-anchor="none" style="mix-blend-mode: normal"><path d="M0,172v-172h172v172z" fill="none"></path><g fill="#ffffff"><path d="M34.4,17.2c-3.16643,0 -5.73333,2.5669 -5.73333,5.73333c-0.00001,0.00747 -0.00001,0.01493 0,0.0224v63.04427v63.04427c-0.00001,0.00746 -0.00001,0.01493 0,0.02239c0,3.16643 2.5669,5.73333 5.73333,5.73333c1.19346,-0.00345 2.3561,-0.37925 3.32578,-1.075l0.0112,0.0112l113.71485,-62.52917c2.03773,-0.93223 3.34559,-2.96619 3.34817,-5.20703c0.00115,-2.30642 -1.37987,-4.38898 -3.50495,-5.28542l-113.55807,-62.45078h-0.0112c-0.97102,-0.69177 -2.13354,-1.06362 -3.32578,-1.0638z"></path></g></g></svg>`
pause = true
}
}
const barraProcesso= document.querySelector(`[wm-progresso=${id}]`)
const temporizador = document.querySelector(`[wm-temporizador=${id}`)
const currentTime = (video.currentTime/100).toFixed(2)
const duracao = (video.duration/100).toFixed(2)
barraProcesso.oninput = function() {
var rMin = this.min;
var rMax = this.max;
var rStep = this.step;
var prop = (rMax-rMin)/rStep; // calcula o número de steps
var perc = 100*((this.value-rMin)/rStep)/prop; //calcula percentual proporcional
// aplica o background: note que deve-se repetir a mesma cor não deixando-a sozinha para que ele faça uma cor solida de cada e não um degradê entre elas.
this.style.background = 'linear-gradient(to right, yellow 0%, yellow '+ perc +'%, darkgray '+ perc +'%, darkgray 100%)';
///==> altera progresso do vídeo de acordo com o "click" do usuário <==/
//transformo o valor da barra de processo em um compatível com o do current do vídeo e pego o valor dele dividido pela duração do video.
const barraProCompativelCurrent = (barraProcesso.value/100)*(video.duration/100)*100
video.currentTime = barraProCompativelCurrent
}
///==> responsável pela atualização da barra de progresso ao decorrer do tempo <==/
setInterval(() => {
//tive que repetir as constantes pois essas precisan ter seu valor atualizado a todo momento.
let baProTransformada = ((barraProcesso.value/100)*((video.duration/100).toFixed(2))).toFixed(2)
const currentTime = (video.currentTime/100).toFixed(2)
const duracao = (video.duration/100).toFixed(2)
const percentual = (video.currentTime/ video.duration) * 100
baProTransformada = ((baProTransformada/duracao)*100)
barraProcesso.value = percentual
// adiciona o background: as 3(três) primeiras cores referem-se ao progresso atual do vídeo, as 2 (duas) ultimas ao fundo da barra.
barraProcesso.style.background = `linear-gradient(to right, yellow 0%, yellow 0% , yellow ${baProTransformada}%, darkgray ${baProTransformada}%, darkgray 100%)`;
temporizador.innerHTML = `${currentTime}/${duracao}`
},1000)
}
controlarVideo("meuVideo")
</script>
</body>
</html>
<!-- Completo e funcionando! por Ysh-rael.-->