-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
executable file
·43 lines (32 loc) · 1 KB
/
script.js
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
32
33
34
35
36
37
38
39
40
41
42
43
/*
$(window).keydown(function (event) {
if (event.keyCode == 111) {
event.preventDefault();
return false;
}
});
*/
function playSound(e) {
/*
if (event.keyCode == 111) {
event.preventDefault();
document.getElementById('111').play();
return false;
}
*/
event.preventDefault();
const audio = document.querySelector(`audio[data-key="${e.key}"]`);
const curKey = document.querySelector(`.wkey[data-key="${e.key}"],.bkey[data-key="${e.key}"]`);
if (!audio) return; // stop the function from running altogether
audio.currentTime = 0; // rewind to the start
audio.pause();
audio.play();
curKey.classList.add('playing');
}
function removeTransition(e) {
if (e.propertyName !== 'transform') return; // skip if not transform
this.classList.remove('playing');
}
const keys = document.querySelectorAll('.wkey, .bkey');
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
window.addEventListener('keydown', playSound);