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 fe83039 commit ad9c58bCopy full SHA for ad9c58b
01 - JavaScript Drum Kit/index-START.html
@@ -58,7 +58,24 @@
58
<audio data-key="76" src="sounds/tink.wav"></audio>
59
60
<script>
61
+ function removeTransition(e) {
62
+ if (e.propertyName !== 'transform') return;
63
+ e.target.classList.remove('playing');
64
+ }
65
66
+ function playSound(e) {
67
+ const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
68
+ const key = document.querySelector(`.key[data-key="${e.keyCode}"]`);
69
+
70
+ if(!audio) return;
71
+ key.classList.add('playing');
72
+ audio.currentTime = 0;
73
+ audio.play();
74
75
76
+ const keys = Array.from(document.querySelectorAll('.key'));
77
+ keys.forEach(key => key.addEventListener('transitionend', removeTransition));
78
+ window.addEventListener( 'keydown', playSound);
79
</script>
80
81
0 commit comments