-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
60 lines (51 loc) · 1.34 KB
/
app.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
let m = document.querySelector('#m');
let d = document.querySelector('#d');
let c = document.querySelector('#c');
let mSnd = document.querySelector('#m_snd');
let dSnd = document.querySelector('#d_snd');
let cSnd = document.querySelector('#c_snd');
let nav = document.querySelector('.navbar');
let menu = document.querySelector('.navbar .dropdown');
let menuBtn = menu.querySelector('.btn');
mSnd.volume = 0.2;
dSnd.volume = 0.2;
cSnd.volume = 0.2;
let keys = [m,d,c];
let notes = {
m: mSnd,
d: dSnd,
c: cSnd
}
function playNote(event) {
let group = event.target.closest('g');
let noteName = group.id;
notes[noteName].currentTime = 0;
notes[noteName].play();
group.style.transform = 'translate(4px,4px)';
setTimeout(() => {
liftKey(event);
}, 750);
}
function liftKey(event) {
let group = event.target.closest('g');
group.style.transform = '';
}
keys.forEach((key) => {
key.addEventListener('mousedown', playNote);
});
document.body.addEventListener('click', (event) => {
if (event.target === menu || event.target === menuBtn) {
menu.classList.toggle('dropdown-open');
} else {
if (menu.classList.contains('dropdown-open')) {
menu.classList.toggle('dropdown-open');
}
}
});
document.addEventListener('scroll', (event) => {
if (window.scrollY > 0) {
nav.classList.add('shadow-2xl');
} else {
nav.classList.remove('shadow-2xl');
}
});