-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (57 loc) · 1.77 KB
/
index.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
61
62
63
window.addEventListener('load', () => {
const sounds = document.querySelectorAll('.sound');
const pads = document.querySelectorAll('.pads div');
const visual = document.querySelector('.visual');
const colors = [
'#60d394' ,
'#d36060' ,
'#c060d3' ,
'#d3d160' ,
'#6860d3' ,
'#60b2d3'
];
const keys = [
'KeyA' ,
'KeyS' ,
'KeyD' ,
'KeyJ' ,
'KeyK' ,
'KeyL'
];
pads.forEach((pad , index) => {
pad.addEventListener('click', function(){
sounds[index].currentTime = 0;
sounds[index].play();
createBubbles(index);
});
window.addEventListener('keydown' , function(e){
if(e.code == keys[index])
{
sounds[index].currentTime = 0;
sounds[index].play();
createBubbles(index);
console.log(e.code);
}
});
});
const createBubbles = index => {
const bubble = document.createElement('div');
visual.appendChild(bubble);
bubble.style.background = colors[index];
bubble.style.animation = "jump 1s ease";
bubble.addEventListener('animationend' , function(){
visual.removeChild(this);
})
};
});
const fullscreen = document.querySelector('.fullscreen');
fullscreen.addEventListener('click' , () =>{
if(!document.fullscreenElement){
document.documentElement.requestFullscreen();
document.getElementById('fullscreenIcon').src = './svg/compress-arrows-alt-solid.svg';
}
else{
document.exitFullscreen();
document.getElementById('fullscreenIcon').src = './svg/fullscreen.svg';
}
});