forked from wesbos/JavaScript30
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
35 lines (29 loc) · 691 Bytes
/
script.js
File metadata and controls
35 lines (29 loc) · 691 Bytes
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
function playAudio(event) {
event.preventDefault();
const button = event.currentTarget;
button.classList.add('playing');
new Audio(button.children.audio.src).play();
setTimeout(function() {
button.classList.remove('playing');
}, 100);
}
window.addEventListener('keydown', event => {
event.preventDefault();
const keys = {
a: 'clap',
s: 'hhat',
d: 'kick',
f: 'openhat',
g: 'boom',
h: 'ride',
j: 'snare',
k: 'tom',
l: 'tink'
};
if(!(event.key in keys)) {
return;
}
const playButton = document.getElementById(keys[event.key]);
playButton.dispatchEvent(new Event("click"))
// new Audio(playButtonAudioSrc).play();
});