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