Created
January 3, 2017 16:33
-
-
Save schalkneethling/88e79ade77b562629769243c5585d900 to your computer and use it in GitHub Desktop.
My code tweak for the Javascript30 by Wes Bos day 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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