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