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