-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·73 lines (61 loc) · 1.88 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
61
62
63
64
65
66
67
68
69
70
71
72
73
const bruhValue = 0.014;
const start = document.querySelector("#start");
const enter = document.querySelector("#enter");
const waveParent = [...document.querySelectorAll(".wave")];
const computer = document.querySelector("#computer");
const btn = document.querySelector("#sound-btn").childNodes;
let isComputerOn = false;
let wave;
function createChild(whichWave) {
const fragment = document.createDocumentFragment();
for (let i = 1; i <= 100; i++) {
const waveChild = document.createElement("div");
waveChild.classList.add(i);
waveChild.classList.add("wave-child");
fragment.appendChild(waveChild);
}
requestAnimationFrame(() => {
whichWave.appendChild(fragment);
wave = document.querySelectorAll(".wave-child");
// Wave animation
wave.forEach((x) => {
let value = ([...x.classList][0] * bruhValue).toFixed(2) + "s";
x.style.animationDelay = value;
});
});
}
function changeScreen() {
document.documentElement.requestFullscreen();
start.classList.add("slide-up");
computer.classList.add("slide-down");
computer.style.display = "grid";
isComputerOn = true;
}
function enterAnim(e) {
if (e.key === "Enter") {
enter.classList.add("active");
setTimeout(() => {
enter.classList.remove("active");
changeScreen();
}, 100);
}
document.removeEventListener("keypress", enterAnim);
}
enter.addEventListener("click", changeScreen, { once: true });
document.addEventListener("keypress", enterAnim);
document.addEventListener("keypress", (e) => {
const audios = ["b", "c", "d", "e", "f"];
const keyPressed = e.key.toLowerCase();
if (isComputerOn && audios.includes(keyPressed)) {
document.getElementById(keyPressed).play();
}
});
btn.forEach((x) => {
x.addEventListener("click", () => {
document.getElementById(x.textContent.toLowerCase()).play();
});
});
document.addEventListener("DOMContentLoaded", () => {
createChild(waveParent[0]);
createChild(waveParent[1]);
});