Skip to content

Instantly share code, notes, and snippets.

@schalkneethling
Created January 3, 2017 16:33
Show Gist options
  • Save schalkneethling/88e79ade77b562629769243c5585d900 to your computer and use it in GitHub Desktop.
Save schalkneethling/88e79ade77b562629769243c5585d900 to your computer and use it in GitHub Desktop.
My code tweak for the Javascript30 by Wes Bos day 1
let keys = document.querySelector('.keys');
keys.addEventListener('transitionend', function(e) {
if (e.propertyName === 'transform') {
e.target.classList.remove('playing');
}
});
function playPercussion(e) {
const audioTrack = document.querySelector(`audio[data-key="${e.keyCode}"]`);
const percussion = document.querySelector(`div[data-key="${e.keyCode}"]`);
if (audioTrack) {
audioTrack.currentTime = 0;
audioTrack.play();
percussion.classList.add('playing');
}
}
window.addEventListener('keydown', playPercussion);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment