1 parent 38e6fc6 commit 97558abCopy full SHA for 97558ab
1 file changed
01 - JavaScript Drum Kit/index.html
@@ -59,14 +59,14 @@
59
60
<script>
61
62
-window.addEventListener("keydown", function (e) {
+function playSound(e) {
63
const audio = document.querySelector(`audio[data-key='${e.keyCode}']`);
64
const key = document.querySelector(`.key[data-key='${e.keyCode}']`);
65
if(!audio) return;
66
audio.currentTime = 0; //rewind to start
67
audio.play()
68
key.classList.add('playing')
69
- });
+};
70
71
function removeTransition(e) {
72
if (e.propertyName !== 'transform') return;
@@ -76,7 +76,7 @@
76
const keys = document.querySelectorAll('.key');
77
78
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
79
-
+window.addEventListener("keydown", playSound);
80
</script>
81
82
0 commit comments