-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnavBar.js
More file actions
45 lines (37 loc) · 1.07 KB
/
navBar.js
File metadata and controls
45 lines (37 loc) · 1.07 KB
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
customElements.define(
"nav-bar",
class extends HTMLElement {
constructor() {
super();
}
connectedCallback() {
const barContainer = document.createElement("div");
barContainer.id = "navContainer";
[
["home", "/"],
["blog", "blog.html"],
["resume", "resume.html"],
].forEach(([title, href]) => {
const div = document.createElement("div");
div.classList.add("navButton");
const a = document.createElement("a");
a.href = href;
a.textContent = title;
a.addEventListener("mouseenter", () => {
const angle = Math.random() * 20 - 10;
a.style.transform = `rotate(${angle}deg)`;
});
a.addEventListener("mouseleave", () => {
a.style.transform = "";
});
div.appendChild(a);
barContainer.appendChild(div);
});
const link = document.createElement("link");
link.rel = "stylesheet";
link.href = "navBar.css";
this.appendChild(link);
this.appendChild(barContainer);
}
}
);