Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. // @flow
  2.  
  3. const playAnimation = ({keyCode}) => {
  4. const audio = window.document.querySelector(`audio[data-key="${keyCode}"]`)
  5. if (audio) {
  6. audio.currentTime = 0
  7. audio.play()
  8. window.document
  9. .querySelector(`div.key[data-key="${keyCode}"]`)
  10. .classList
  11. .add('playing')
  12. }
  13. }
  14.  
  15. window.addEventListener('keydown', playAnimation)
  16.  
  17. const resetAnimation = ({
  18. propertyName
  19. , 'target': elt
  20. }) => {
  21. if (propertyName === 'transform') {
  22. elt.classList
  23. .remove('playing')
  24. }
  25. }
  26.  
  27. window.document
  28. .querySelectorAll('div.key')
  29. .forEach(key => key.addEventListener('transitionend', resetAnimation))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement