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 86bade4 commit c830e5fCopy full SHA for c830e5f
01 - JavaScript Drum Kit/index-START.html
@@ -58,7 +58,29 @@
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) {
65
+ return;
66
+ }
67
+ audio.currentTime = 0;
68
+ audio.play();
69
+ // console.log(key);
70
+ key.classList.add('playing');
71
72
+ function removeTransition(e) {
73
+ if (e.propertyName !== 'transform') {
74
75
76
+ console.log(e.propertyName);
77
+ this.classList.remove('playing');
78
79
+ const keys = document.querySelectorAll('.key');
80
+ keys.forEach(key => {
81
+ key.addEventListener('transitionend', removeTransition);
82
+ });
83
+ window.addEventListener('keydown', playSound);
84
</script>
85
86
0 commit comments