-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (37 loc) · 1.11 KB
/
index.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
for (var i = 0; i < document.querySelectorAll(".drum").length; i++) {
document.querySelectorAll("button")[i].addEventListener("click",
function() {
var buttonInnerHTML = this.innerHTML;
makeSound(buttonInnerHTML);
buttonAnimation(buttonInnerHTML);
});
}
document.addEventListener("keydown", function(event) {
makeSound(event.key);
buttonAnimation(event.key);
});
function makeSound(key) {
switch (key) {
case "j":
var buzz = new Audio("./sounds/sound1.mp3");
buzz.play();
break;
case "k":
var closed = new Audio("./sounds/sound2.mp3");
closed.play();
break;
case "l":
var open = new Audio("./sounds/sound3.mp3");
open.play();
break;
default:
break;
}
}
function buttonAnimation(currentKey) {
var activeButton = document.querySelector("." + currentKey);
activeButton.classList.add("pressed");
setTimeout(function() {
activeButton.classList.remove("pressed");
}, 100);
}