-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
80 lines (59 loc) · 1.82 KB
/
Copy pathscript.js
File metadata and controls
80 lines (59 loc) · 1.82 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
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
76
77
78
79
fetch("header.html")
.then(response => response.text())
.then(data => {
document.getElementById("header").innerHTML = data;
initHeaderScripts();
});
fetch("footer.html")
.then(response => response.text())
.then(data => {
document.getElementById("footer").innerHTML = data;
// Now that footer exists, run footer-related JS
initFooterScripts();
});
function initHeaderScripts() {
const header = document.querySelector("header");
// Scroll fade effect
window.addEventListener("scroll", () => {
if (window.scrollY > 30) {
header.classList.add("scrolled");
} else {
header.classList.remove("scrolled");
}
});
const btn = document.getElementById("menuButton");
const icon = document.getElementById("menuIcon");
const menu = document.getElementById("mobileMenu");
if (!btn || !icon || !menu) return;
let open = false;
icon.src = "Photos/Menu.png";
btn.addEventListener("click", () => {
open = !open;
icon.src = open ? "Photos/Close.png" : "Photos/Menu.png";
menu.classList.toggle("open", open);
});
}
function initFooterScripts() {
const base = document.querySelector(".img-stack");
if (!base) return;
const totalFrames = 9;
const crankFrames = [];
for (let i = 1; i <= totalFrames; i++) {
crankFrames.push(`Photos/crank/${i}.png`);
}
let frameIndex = 0;
let cursorInterval = null;
base.addEventListener("mouseenter", () => {
const frameTime = 1000 / crankFrames.length;
cursorInterval = setInterval(() => {
document.body.style.cursor = `url(${crankFrames[frameIndex]}) 24 24, auto`;
frameIndex = (frameIndex + 1) % crankFrames.length;
}, frameTime);
});
base.addEventListener("mouseleave", () => {
clearInterval(cursorInterval);
cursorInterval = null;
frameIndex = 0;
document.body.style.cursor = "auto";
});
}