-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
32 lines (28 loc) · 833 Bytes
/
main.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
function tocaSom (id){
const elemento = document.querySelector(id);
if (elemento == null){
console.log("elemento nao encontrado")
}
if(elemento != null){
if(elemento.localName === 'audio'){
elemento.play()
}
}
}
const listaDeTeclas = document.querySelectorAll('.tecla');
for (let indice = 0; indice < listaDeTeclas.length; indice++) {
const tecla = listaDeTeclas[indice];
const instrumento = tecla.classList[1]
const idAudio = `#som_${instrumento}`
tecla.onclick = function () {
tocaSom(idAudio);
}
tecla.onkeydown = function (evento) {
if(evento.code === "Enter" || evento.code === "Space") {
tecla.classList.add('ativa');
}
}
tecla.onkeyup = function () {
tecla.classList.remove('ativa');
}
}