-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
72 lines (59 loc) · 1.62 KB
/
Copy pathscript.js
File metadata and controls
72 lines (59 loc) · 1.62 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
for(var i=0;i<document.querySelectorAll("button").length;i++)
{
document.querySelectorAll("button")[i].addEventListener("click",function()
{
var butHtml = this.innerHTML;
console.log(butHtml);
makesound(butHtml);
});
}
document.addEventListener("keypress", function(event) {
console.log(event.key);
makesound(event.key);
animate(event.key);
});
function animate(key)
{
var selectedclass = "."+key;
document.querySelector(selectedclass).classList.add("opacity");
setTimeout(function(){
document.querySelector(selectedclass).classList.remove("opacity");
},100
);
}
function makesound(key)
{
switch(key)
{
case "w":
var a1 = new Audio("sound/sounds_tom-1.mp3");
a1.play();
break;
case "a":
var a2 = new Audio("sound/sounds_tom-2.mp3");
a2.play();
break;
case "s":
var a3 = new Audio("sound/sounds_tom-3.mp3");
a3.play();
break;
case "d":
var a4 = new Audio("sound/sounds_tom-4.mp3");
a4.play();
break;
case "j":
var a5 = new Audio("sound/sounds_snare.mp3");
a5.play();
break;
case "k":
var a6 = new Audio("sound/sounds_crash.mp3");
a6.play();
break;
case "l":
var a7 = new Audio("sound/sounds_kick-bass.mp3");
a7.play();
break;
default:
break;
}
}