Skip to content

Commit

Permalink
Complete day1
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenyunZhang committed Mar 8, 2024
1 parent 7c04fd5 commit 6012f9f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions 01 - JavaScript Drum Kit/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,23 @@
<audio data-key="76" src="sounds/tink.wav"></audio>

<script>
function playSound(e) {
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`)
const key = document.querySelector(`.key[data-key="${e.keyCode}"]`)
if(!audio) return;
audio.currentTime = 0;
audio.play();
key.classList.add('playing');
}

function removeTransition(e){
if(e.propertyName != 'transform') return;
this.classList.remove('playing');
}

const keys = document.querySelectorAll('.key')
keys.forEach(key => key.addEventListener('transitionend', removeTransition))
window.addEventListener('keydown', playSound);
</script>


Expand Down

0 comments on commit 6012f9f

Please sign in to comment.