diff --git a/01 - JavaScript Drum Kit/app.js b/01 - JavaScript Drum Kit/app.js new file mode 100644 index 0000000000..6a079b268f --- /dev/null +++ b/01 - JavaScript Drum Kit/app.js @@ -0,0 +1,22 @@ +const removeTransition = (e) => { + if (e.propertyName == "transform") { + e.target.classList.remove("playing"); + } +}; + +const playSound = (e) => { + const audioSoundBtn = document.querySelector( + `audio[data-key="${e.key.toUpperCase()}"]` + ); + const key = document.querySelector(`div[data-key="${e.key.toUpperCase()}"]`); + if (audioSoundBtn) { + key.classList.add("playing"); + audioSoundBtn.currentTime = 0; + audioSoundBtn.play(); + } +}; +const keys = document.querySelectorAll(".key"); +keys.forEach((key) => { + key.addEventListener("transitionend", removeTransition); +}); +window.addEventListener("keydown", playSound); diff --git a/01 - JavaScript Drum Kit/index-START.html b/01 - JavaScript Drum Kit/index-START.html index 4070d32767..1e96a1e846 100644 --- a/01 - JavaScript Drum Kit/index-START.html +++ b/01 - JavaScript Drum Kit/index-START.html @@ -7,60 +7,56 @@
-