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 5029405 commit fe32705Copy full SHA for fe32705
01 - JavaScript Drum Kit/index-START.html
@@ -58,7 +58,21 @@
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
+ audio.currentTime = 0;
66
+ audio.play();
67
+ key.classList.toggle('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
+ window.addEventListener('keydown', playSound);
76
</script>
77
78
0 commit comments