Skip to content

Commit ca38117

Browse files
committed
one complete
1 parent 5029405 commit ca38117

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

01 - JavaScript Drum Kit/index-START.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,30 @@
5959

6060
<script>
6161

62+
//HJW
63+
function playSound(e){
64+
console.log(e.keyCode);
65+
const audio = document.querySelector(`audio[data-key="${e.keyCode}"`);
66+
const key = document.querySelector(`.key[data-key="${e.keyCode}"`);
67+
console.log(audio);
68+
if (!audio) return;
69+
console.log(key);
70+
audio.currentTime = 0;
71+
audio.play();
72+
key.classList.add('playing');
73+
}
74+
75+
function removeTransition(e){
76+
if (e.propertyName !== 'transform') return;
77+
console.log(e.propertyName);
78+
console.log(this);
79+
this.classList.remove('playing');
80+
}
81+
82+
const keys = document.querySelectorAll('.key')
83+
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
84+
window.addEventListener('keydown', playSound);
85+
6286
</script>
6387

6488

0 commit comments

Comments
 (0)