-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
152 lines (135 loc) · 5.54 KB
/
Copy pathscript.js
File metadata and controls
152 lines (135 loc) · 5.54 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* ===== Nav: scroll state + mobile toggle ===== */
const nav = document.getElementById("nav");
const navToggle = document.getElementById("navToggle");
const navLinks = document.querySelector(".nav-links");
addEventListener("scroll", () => {
nav.classList.toggle("scrolled", scrollY > 40);
}, { passive: true });
navToggle?.addEventListener("click", () => {
const open = navLinks.classList.toggle("open");
navToggle.textContent = open ? "Close" : "Menu";
});
navLinks?.querySelectorAll("a").forEach((a) =>
a.addEventListener("click", () => {
navLinks.classList.remove("open");
navToggle.textContent = "Menu";
})
);
/* ===== Scroll reveal (staggered) ===== */
const io = new IntersectionObserver((entries) => {
entries.forEach((e, i) => {
if (e.isIntersecting) {
e.target.style.transitionDelay = Math.min(i * 60, 240) + "ms";
e.target.classList.add("visible");
io.unobserve(e.target);
}
});
}, { threshold: 0.14, rootMargin: "0px 0px -8% 0px" });
document.querySelectorAll(".reveal").forEach((el) => io.observe(el));
/* ===== Hero line reveal on load ===== */
addEventListener("DOMContentLoaded", () => {
const lines = document.querySelectorAll(".hero-title .line-in");
lines.forEach((l, i) => {
l.style.transitionDelay = 120 + i * 120 + "ms";
requestAnimationFrame(() => requestAnimationFrame(() => l.classList.add("in")));
});
});
/* ===== Scroll progress + parallax (rAF-throttled) ===== */
const reduce = matchMedia("(prefers-reduced-motion: reduce)").matches;
const progress = document.getElementById("scrollProgress");
const parallaxEls = [...document.querySelectorAll("[data-parallax]")].map((el) => ({
el, speed: parseFloat(el.dataset.parallax),
}));
let ticking = false;
function onScroll() {
const scrolled = scrollY;
const max = document.documentElement.scrollHeight - innerHeight;
if (progress) progress.style.width = (max > 0 ? (scrolled / max) * 100 : 0) + "%";
if (!reduce) {
const mid = scrolled + innerHeight / 2;
for (const p of parallaxEls) {
const r = p.el.getBoundingClientRect();
const center = r.top + scrolled + r.height / 2;
const offset = (mid - center) * p.speed;
p.el.style.transform = `translate3d(0, ${offset.toFixed(1)}px, 0)`;
}
}
ticking = false;
}
addEventListener("scroll", () => {
if (!ticking) { requestAnimationFrame(onScroll); ticking = true; }
}, { passive: true });
addEventListener("resize", onScroll, { passive: true });
onScroll();
/* ===== Magnetic links ===== */
if (!reduce && matchMedia("(pointer:fine)").matches) {
document.querySelectorAll("[data-magnetic]").forEach((el) => {
const strength = 0.35;
el.addEventListener("mousemove", (e) => {
const r = el.getBoundingClientRect();
const x = (e.clientX - (r.left + r.width / 2)) * strength;
const y = (e.clientY - (r.top + r.height / 2)) * strength;
el.style.transform = `translate(${x.toFixed(1)}px, ${y.toFixed(1)}px)`;
});
el.addEventListener("mouseleave", () => { el.style.transform = ""; });
});
}
/* ===== Smooth eased anchor scroll ===== */
const easeInOutCubic = (t) => (t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2);
function smoothScrollTo(targetY, duration = 850) {
const startY = scrollY;
const dist = targetY - startY;
let start;
function step(ts) {
if (start === undefined) start = ts;
const p = Math.min((ts - start) / duration, 1);
scrollTo(0, startY + dist * easeInOutCubic(p));
if (p < 1) requestAnimationFrame(step);
}
requestAnimationFrame(step);
}
document.querySelectorAll('a[href^="#"]').forEach((a) => {
a.addEventListener("click", (e) => {
const id = a.getAttribute("href");
if (id === "#" || id === "#top") { e.preventDefault(); reduce ? scrollTo(0, 0) : smoothScrollTo(0); return; }
const target = document.querySelector(id);
if (!target) return;
e.preventDefault();
const y = target.getBoundingClientRect().top + scrollY - 64;
reduce ? scrollTo(0, y) : smoothScrollTo(y);
});
});
/* ===== Custom cursor ===== */
if (matchMedia("(pointer:fine)").matches) {
const dot = document.createElement("div");
const ring = document.createElement("div");
dot.className = "cursor-dot";
ring.className = "cursor-ring";
document.body.append(dot, ring);
document.body.classList.add("cursor-active"); // now safe to hide native cursor
let mx = innerWidth / 2, my = innerHeight / 2; // mouse
let rx = mx, ry = my; // ring (lerped)
addEventListener("mousemove", (e) => {
mx = e.clientX; my = e.clientY;
dot.style.transform = `translate(${mx}px, ${my}px) translate(-50%, -50%)`;
});
(function loop() {
rx += (mx - rx) * 0.18;
ry += (my - ry) * 0.18;
ring.style.transform = `translate(${rx}px, ${ry}px) translate(-50%, -50%)`;
requestAnimationFrame(loop);
})();
// Grow ring over interactive elements
const hoverSel = "a, button, [data-magnetic], .venture-row, .chip";
document.querySelectorAll(hoverSel).forEach((el) => {
el.addEventListener("mouseenter", () => ring.classList.add("hover"));
el.addEventListener("mouseleave", () => ring.classList.remove("hover"));
});
addEventListener("mousedown", () => ring.classList.add("down"));
addEventListener("mouseup", () => ring.classList.remove("down"));
// Hide when leaving the window
addEventListener("mouseleave", () => { dot.style.opacity = ring.style.opacity = "0"; });
addEventListener("mouseenter", () => { dot.style.opacity = ring.style.opacity = "1"; });
}
/* ===== Footer year ===== */
document.getElementById("year").textContent = new Date().getFullYear();