-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathapp.js
More file actions
32 lines (29 loc) · 867 Bytes
/
Copy pathapp.js
File metadata and controls
32 lines (29 loc) · 867 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
32
// Template
const appDiv = document.getElementById("app");
const valueText = document.getElementById("value");
window.onkeypress = rKey;
const clickArea = document.getElementById("clickArea");
clickArea.addEventListener("click", eventAction);
// Functions
// --------------------------------- //
// Template
function updateTemplate(text, randomBackgroundColor) {
valueText.innerHTML = text;
clickArea.className = "fade-in";
appDiv.style.backgroundColor = "#" + randomBackgroundColor;
}
// --------------------------------- //
// Capturing keys
function rKey(e) {
if (e && e.code === "KeyR") {
eventAction();
}
}
function eventAction() {
appDiv.style.backgroundColor = "#FFF";
clickArea.className = "fade-out";
setTimeout(async () => {
const { adj, color } = await (await fetch("./api")).json();
updateTemplate(adj, color);
}, 400);
}