-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.js
More file actions
31 lines (29 loc) · 1015 Bytes
/
javascript.js
File metadata and controls
31 lines (29 loc) · 1015 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
let removeTransition = (e) => {
if (e.propertyName !== 'transform') return;
e.target.classList.remove('playing');
}
let playSound = (e) => {
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
const key = document.querySelector(`a[data-key="${e.keyCode}"]`);
if (!audio) return;
key.classList.add('playing');
audio.currentTime = 0;
audio.play();
}
let playThis = (obj)=>{
const audioz = document.querySelector(`audio[data-key="${obj.getAttribute('data-key')}"]`);
const keyz = document.querySelector(`a[data-key="${obj.getAttribute('data-key')}"]`);
if (!audioz) return;
keyz.classList.add('playing');
audioz.currentTime = 0;
audioz.play();
}
const keys = Array.from(document.querySelectorAll('.key'));
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
window.addEventListener('keydown', playSound);
window.onclick = function(e) {
if (!e.target.localName == 'a' || 'kbd' || 'span') return
else {
clickFunction();
}
}