-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
57 lines (51 loc) · 1.57 KB
/
app.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
window.addEventListener('load', () => {
const sounds = document.querySelectorAll('.sound');
const pads = document.querySelectorAll('.pads div');
const kit = document.querySelector('.kit');
pads.forEach((pad, index) => {
pad.addEventListener('click', function() {
sounds[index].currentTime = 0;
sounds[index].play();
});
});
//the drum can be played with the keys A.S,D,J,K,L
document.addEventListener("keydown", function(event) {
makeSound(event.key);
buttonAnimation(event.key);
});
function makeSound(key) {
switch (key) {
case 'a':
var closed_hithat = new Audio('sounds/sound1.mp3');
closed_hithat.play();
break;
case 's':
var kick = new Audio('sounds/sound3.mp3');
kick.play();
break;
case 'd':
var clap = new Audio('sounds/sound4.mp3');
clap.play();
break;
case 'j':
var open_hithat = new Audio('sounds/sound5.mp3');
open_hithat.play();
break;
case 'k':
var snare = new Audio('sounds/sound6.mp3');
snare.play();
break;
case 'l':
var crash = new Audio('sounds/sound2.mp3');
crash.play();
break;
}
}
function buttonAnimation(currentKey) {
var activeButton = document.querySelector("." + currentKey);
activeButton.classList.add("pressed");
setTimeout(function() {
activeButton.classList.remove("pressed");
}, 100);
};
});