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 650e837 commit aaed2f7Copy full SHA for aaed2f7
01 - JavaScript Drum Kit/index-START.html
@@ -58,7 +58,22 @@
58
<audio data-key="76" src="sounds/tink.wav"></audio>
59
60
<script>
61
+ window.addEventListener('keydown', function (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; // stop the function from running all together
65
+ audio.currentTime=0; // rewind to start
66
+ audio.play();
67
+ key.classList.add('playing');
68
+ });
69
70
+function removeTransition(e) {
71
+ if(e.propertyName !== 'transform') return; // skip it if it'snot a transform
72
+ this.classList.remove('playing');
73
+}
74
+
75
+ const keys = document.querySelectorAll('.key');
76
+ keys.forEach(key => key.addEventListener('transitionend', removeTransition))
77
</script>
78
79
0 commit comments