We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 38a754c commit 323e877Copy full SHA for 323e877
1 file changed
01 - JavaScript Drum Kit/index-START.html
@@ -59,6 +59,23 @@
59
60
<script>
61
62
+
63
+function playSound(e) {
64
+ const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
65
+ const key = document.querySelector(`.key[data-key="${e.keyCode}"]`);
66
+ if(!audio) return;
67
+ audio.currentTime = 0;
68
+ audio.play();
69
+ key.classList.add('playing');
70
+}
71
72
+function removeTransition(e) {
73
+ if(e.propertyName !== 'transform') return;
74
+ this.classList.remove('playing');
75
76
+window.addEventListener('keydown', playSound);
77
+const keys = document.querySelectorAll('.key');
78
+keys.forEach(key => key.addEventListener('transitionend', removeTransition));
79
</script>
80
81
0 commit comments