-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (51 loc) · 1.48 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
49
50
51
52
53
54
55
var len = document.querySelectorAll(".drum").length;
for (var i = 0; i < len; i++) {
document.querySelectorAll(".drum")[i].addEventListener(
"click",
function () {
this.style.color = "white";
// setTimeout(function () {
// this.style.color = "white";
// }, 1000);
makeSound(this.innerHTML);
btnanimate(this.innerHTML);
}
// var audio = new Audio("/sounds/" + "arr[i]" + ".mp3");
);
}
document.addEventListener("keydown", function (event) {
makeSound(event.key);
btnanimate(event.key);
});
function makeSound(k) {
if (k === "w") {
var tom1 = new Audio("/DrumKit/sounds/tom-1.mp3");
tom1.play();
} else if (k === "a") {
var tom2 = new Audio("/DrumKit/sounds/tom-2.mp3");
tom2.play();
} else if (k === "s") {
var tom3 = new Audio("/DrumKit/sounds/tom-3.mp3");
tom3.play();
} else if (k === "d") {
var tom4 = new Audio("/DrumKit/sounds/tom-4.mp3");
tom4.play();
} else if (k === "j") {
var tom5 = new Audio("/DrumKit/sounds/crash.mp3");
tom5.play();
} else if (k === "k") {
var tom6 = new Audio("/DrumKit/sounds/kick-bass.mp3");
tom6.play();
} else if (k === "l") {
var tom7 = new Audio("/DrumKit/sounds/snare.mp3");
tom7.play();
} else {
console.log("invalid Key");
}
}
function btnanimate(key) {
document.querySelector("." + key).classList.add("pressed");
setTimeout(function () {
document.querySelector("." + key).classList.remove("pressed");
}, 100);
}