-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
48 lines (41 loc) · 1.49 KB
/
main.js
File metadata and controls
48 lines (41 loc) · 1.49 KB
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
function tocaSom (seletorAudio){
const elemento = document.querySelector(seletorAudio);
if(elemento != null && elemento.localName === 'audio'){
elemento.play();
}
else{
alert('Non Ecziste');
}
}
const listaDeTeclas = document.querySelectorAll('.tecla');
for (let contador = 0; contador<listaDeTeclas.length; contador++){
const tecla = listaDeTeclas[contador];
const instrumento = tecla.classList[1];
const idAudio = `#som_${instrumento}`;
tecla.onclick = function(){
tocaSom(idAudio);
}
tecla.onkeydown = function(evento){
if(evento.code === 'Space' || evento.code === 'Enter'){
tecla.classList.add('ativa');
}
}
tecla.onkeyup = function(){
tecla.classList.remove('ativa');
}
}
function tocaSomTom(){
document.querySelector('#som_tecla_tom').play();
document.querySelector('#som_tecla_pom').pause();
document.querySelector('#som_tecla_clap').pause();
document.querySelector('#som_tecla_tim').pause()
document.querySelector('#som_tecla_puff').pause();
document.querySelector('#som_tecla_splash').pause();
document.querySelector('#som_tecla_toim').pause();
document.querySelector('#som_tecla_psh').pause();
document.querySelector('#som_tecla_tic').pause();
document.querySelector('#som_tecla_t').pause();
document.querySelector('#som_tecla_i').pause();
document.querySelector('#som_tecla_c').pause();
}
document.querySelector('.tecla_tom').onclick = tocaSomTom;