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