-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
24 lines (18 loc) · 737 Bytes
/
script.js
File metadata and controls
24 lines (18 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
window.addEventListener('keydown',function(e){
console.log(e.keyCode);
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
const key = document.querySelector(`.key[data-key="${e.keyCode}"]`)
if(!audio) return ;
// console.log(audio);
audio.currentTime=0;
audio.play();
console.log(key);
key.classList.add('playing');
});
function removeTransition(e){
if(e.propertyName !== 'transform') return ;
console.log(e.propertyName);
this.classList.remove('playing');
}
const keys = document.querySelectorAll('.key');
keys.forEach(key => key.addEventListener('transitionend',removeTransition));