Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
121 lines (86 loc) · 2.91 KB
/
Copy pathscript.js
File metadata and controls
121 lines (86 loc) · 2.91 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* Logo typewriter effect */
const logo = document.getElementById("logo");
const text = logo.textContent;
logo.textContent = "";
const speed = 40; // ms per character
let i = 0;
function type() {
if (i < text.length) {
logo.textContent += text.charAt(i);
i++;
setTimeout(type, speed);
}
}
type();
/* First page load nav link fade in */
document.addEventListener("DOMContentLoaded", () => {
if (localStorage.getItem("FirstLoadEver")) {
document.body.classList.add("no-fade");
} else {
localStorage.setItem("FirstLoadEver", "true");
}
});
/* Nav color change after scroll 10px */
document.addEventListener("scroll", () => {
const nav = document.querySelector("nav");
if (window.scrollY > 10) {
nav.classList.add("scrolled");
} else {
nav.classList.remove("scrolled");
nav.classList.remove("black"); // reset completely
}
});
/* Intersection for black state */
const el = document.getElementById("black-intersection");
let wasBelow = false;
function checkIntersection() {
if (!el) return;
const rect = el.getBoundingClientRect();
const top = rect.top;
const threshold = window.innerHeight * 0.40; // 40vh line
const isBelow = top <= threshold;
const nav = document.querySelector("nav");
// Crossing downward → add .black while keeping .scrolled
if (isBelow && !wasBelow) {
console.log("black intersection");
nav.classList.add("black");
}
// Crossing upward → remove .black, keep .scrolled
if (!isBelow && wasBelow) {
console.log("above intersection");
nav.classList.remove("black");
}
wasBelow = isBelow;
}
document.addEventListener("scroll", checkIntersection, { passive: true });
window.addEventListener("resize", checkIntersection);
// ----------------- *** Mobile nav activator
// Simple toggle for mobile nav
const menuToggle = document.querySelector('.mobile-nav .menu-toggle');
const mobileNav = document.querySelector('.mobile-nav');
menuToggle.addEventListener('click', () => {
mobileNav.classList.toggle('open');
});
/* sticky text during 3d scene */
document.addEventListener("scroll", () => {
const canvas = document.getElementById("canvas-target");
const section = document.getElementById("three-section");
const scrollY = window.scrollY;
const sectionTop = section.offsetTop;
const sectionBottom = sectionTop + section.offsetHeight;
// Turn on after scrolling past one full viewport (100vh from the very top)
if (scrollY >= window.innerHeight && scrollY < sectionBottom - window.innerHeight) {
canvas.style.position = "fixed";
canvas.style.top = "0";
canvas.style.left = "0";
canvas.style.width = "100%";
canvas.style.height = "100vh";
} else {
// Reset back into flow so it scrolls out naturally
canvas.style.position = "absolute";
canvas.style.top = "0";
canvas.style.left = "0";
canvas.style.width = "100%";
canvas.style.height = "100vh";
}
});