-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
19 lines (14 loc) · 753 Bytes
/
index.js
File metadata and controls
19 lines (14 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
window.addEventListener('keydown',function(e){
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
const key = document.querySelector(`.key[data-key="${e.keyCode}"]`);
if(!audio)return;// stops the function from running as there is no audio file associated with the key
audio.currentTime = 0; //rewinds the audio to the start to allow multiple inputs within the time frame
audio.play();
key.classList.toggle('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));
})