-
Notifications
You must be signed in to change notification settings - Fork 0
/
addMenu.js
75 lines (68 loc) · 1.91 KB
/
addMenu.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
74
75
// let pages = ["contact", "games", "work", "teaching", "about"];
let pages = ["about", "work", "teaching", "games", "contact"];
let menuStyles = {};
// let homeStyles = {
// position: "fixed",
// top: "10px",
// left: "20px",
// height: "45px",
// width: "45px",
// "background-image": "URL(images/fancyZ.png)",
// "background-size": "contain",
// "background-position": "center",
// };
let barStyles = {};
buildMenu(document.body);
applyListeners();
function buildMenu(buildTarget) {
let menuDiv = document.createElement("div");
menuDiv.id = "menuDiv";
menuDiv.classList.add("menuDiv");
repeat(() => {
let bar = document.createElement("div");
// applyStyles(bar, barStyles);
bar.classList.add("blackBar");
menuDiv.appendChild(bar);
}, 3);
buildTarget.appendChild(menuDiv);
let homeDiv = document.createElement("a");
homeDiv.href = "home.html";
homeDiv.id = "homeDiv";
homeDiv.classList.add("homeButton");
// applyStyles(homeDiv, homeStyles);
buildTarget.appendChild(homeDiv);
let menuBar = document.createElement("div");
menuBar.id = "menuBar";
menuBar.classList.add("menuBar");
repeat((c) => {
let page = pages[c - 1];
let link = document.createElement("a");
link.href = `${page}.html`;
link.innerHTML = `
<img src="images/${page}.png" />
<span>${page.toUpperCase()}</span>
`;
menuBar.appendChild(link);
}, pages.length);
// applyStyles(menuBar, menuBarStyles);
buildTarget.appendChild(menuBar);
}
function repeat(func, x = 0) {
let count = 1;
while (count <= x) {
func(count);
count++;
}
}
function applyStyles(target, styles) {
for (let style in styles) {
target.style[style] = styles[style];
}
}
function applyListeners() {
let target = document.getElementById("menuBar");
menuDiv.addEventListener("click", function (e) {
// console.log("click");
target.classList.toggle("menuBarVisible");
});
}