-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (39 loc) · 1.12 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
56
57
var insts = document.querySelectorAll(".instrument");
for(var i = 0; i < insts.length; i++)
insts[i].addEventListener("click", playAudio);
function playAudio(){
var audioId = "aud-" + this.id;
var imgId = "img-" + this.id;
document.getElementById(imgId).classList.add("pressed");
setTimeout(function () {
document.getElementById(imgId).classList.remove("pressed");
}, 200);
document.getElementById(audioId).play();
}
document.querySelector("body").addEventListener("keydown", keyPress);
function keyPress(key){
//alert(key.which);
switch(key.which){
case 81:
document.getElementById("crash").click();
break;
case 87:
document.getElementById("kick").click();
break;
case 69:
document.getElementById("snare").click();
break;
case 82:
document.getElementById("tom1").click();
break;
case 65:
document.getElementById("tom2").click();
break;
case 83:
document.getElementById("floor-tom1").click();
break;
case 68:
document.getElementById("floor-tom2").click();
break;
}
}