We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b8bc9cb commit d69cc36Copy full SHA for d69cc36
1 file changed
01 - JavaScript Drum Kit/index-START.html
@@ -58,6 +58,20 @@
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;
65
+ audio.currentTime = 0; //rewind
66
+ audio.play();
67
+ key.classList.add('playing');
68
+ })
69
+function removeTransition(e){
70
+ if(e.propertyName != 'transform') return;
71
+ this.classList.remove('playing')
72
+}
73
+const keys = document.querySelectorAll('.key');
74
+keys.forEach(key => key.addEventListener('transitionend',removeTransition))
75
76
</script>
77
0 commit comments