-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
221 lines (189 loc) · 6.35 KB
/
Copy pathscript.js
File metadata and controls
221 lines (189 loc) · 6.35 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
document.addEventListener("DOMContentLoaded", () => {
// --- BOUNCE NAV LOGIC ---
const menuToggle = document.getElementById("menu-toggle");
const navOverlay = document.querySelector(".nav-overlay");
const navWrapper = document.querySelector(".nav-wrapper");
const navLinks = document.querySelectorAll(".nav-links a");
let isMenuOpen = false;
const openMenu = () => {
isMenuOpen = true;
navOverlay.classList.add("active");
navWrapper.classList.add("open");
menuToggle.textContent = "✕";
document.body.style.overflow = "hidden";
};
const closeMenu = () => {
if (!isMenuOpen) return;
isMenuOpen = false; // Set state immediately
navOverlay.classList.remove("active");
navWrapper.classList.remove("open");
navWrapper.classList.add("closing");
setTimeout(() => {
navWrapper.classList.remove("closing");
}, 600);
menuToggle.textContent = "☰";
document.body.style.overflow = "";
};
if (menuToggle && navOverlay && navWrapper) {
// Toggle Button
menuToggle.addEventListener("click", (e) => {
e.stopPropagation();
if (isMenuOpen) closeMenu();
else openMenu();
});
// Close when clicking outside (on overlay)
navOverlay.addEventListener("click", (e) => {
if (e.target === navOverlay) {
closeMenu();
}
});
// Close when clicking ANY nav link
navLinks.forEach((link) => {
link.addEventListener("click", closeMenu);
});
// Close on Escape key
document.addEventListener("keydown", (e) => {
if (e.key === "Escape" && isMenuOpen) {
closeMenu();
}
});
}
// --- THEME TOGGLE LOGIC ---
const themeToggle = document.querySelector(".theme-toggle-nav");
const html = document.documentElement;
// Check local storage
const storedTheme = localStorage.getItem("theme");
if (storedTheme === "light") {
html.classList.add("light-mode");
if (themeToggle) themeToggle.textContent = "☀️";
} else {
if (themeToggle) themeToggle.textContent = "🌙";
}
if (themeToggle) {
themeToggle.addEventListener("click", () => {
html.classList.toggle("light-mode");
const isLight = html.classList.contains("light-mode");
localStorage.setItem("theme", isLight ? "light" : "dark");
themeToggle.textContent = isLight ? "☀️" : "🌙";
});
}
// --- SCROLL SPY & SIDE NAV (If present) ---
const sections = document.querySelectorAll("section[id]");
const navDots = document.querySelectorAll(".nav-dot");
function scrollActive() {
const scrollY = window.pageYOffset;
sections.forEach((current) => {
const sectionHeight = current.offsetHeight;
const sectionTop = current.offsetTop - 200; // Offset
const sectionId = current.getAttribute("id");
if (scrollY > sectionTop && scrollY <= sectionTop + sectionHeight) {
// Remove active from all dots
navDots.forEach((dot) => dot.classList.remove("active"));
// Add active to current dot
const activeDot = document.querySelector(
`.nav-dot[data-target="${sectionId}"]`,
);
if (activeDot) activeDot.classList.add("active");
}
});
}
if (sections.length > 0 && navDots.length > 0) {
window.addEventListener("scroll", scrollActive);
// Dot click
navDots.forEach((dot) => {
dot.addEventListener("click", () => {
const targetId = dot.getAttribute("data-target");
const targetSection = document.getElementById(targetId);
if (targetSection) {
window.scrollTo({
top: targetSection.offsetTop - 80,
behavior: "smooth",
});
}
});
});
}
// --- SCROLL ANIMATIONS (Intersection Observer) ---
const observerOptions = {
threshold: 0.1,
rootMargin: "0px 0px -50px 0px",
};
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.style.opacity = "1";
entry.target.style.transform = "translateY(0)";
observer.unobserve(entry.target); // Animate once
}
});
}, observerOptions);
// Apply animation to key elements
document
.querySelectorAll(
".hero-title, .hero-subtitle, .project-item, .education-item, .gateway-card",
)
.forEach((el) => {
el.style.opacity = "0";
el.style.transform = "translateY(20px)";
el.style.transition = "opacity 0.6s ease, transform 0.6s ease";
observer.observe(el);
});
// --- MODAL PREVIEW LOGIC ---
const modal = document.getElementById("preview-modal");
const modalFrame = document.getElementById("preview-frame");
const closeBtn = document.querySelector(".close-modal");
const previewBtns = document.querySelectorAll(".preview-btn");
if (modal && modalFrame && closeBtn) {
previewBtns.forEach((btn) => {
btn.addEventListener("click", (e) => {
e.preventDefault();
const url = btn.getAttribute("data-url");
if (url) {
modalFrame.src = url;
modal.classList.add("show");
document.body.style.overflow = "hidden"; // Prevent background scrolling
}
});
});
const closeModal = () => {
modal.classList.remove("show");
document.body.style.overflow = "";
setTimeout(() => {
modalFrame.src = ""; // Stop video/content
}, 300);
};
closeBtn.addEventListener("click", closeModal);
// Close on outside click
window.addEventListener("click", (e) => {
if (e.target === modal) {
closeModal();
}
});
// Close on Escape key
document.addEventListener("keydown", function (event) {
if (event.key === "Escape" && modal.classList.contains("show")) {
closeModal();
}
});
}
// --- CURSOR FOLLOWER LOGIC ---
const follower = document.createElement("div");
follower.classList.add("cursor-follower");
document.body.appendChild(follower);
let mouseX = 0;
let mouseY = 0;
let followerX = 0;
let followerY = 0;
document.addEventListener("mousemove", (e) => {
mouseX = e.clientX;
mouseY = e.clientY;
});
function animateFollower() {
// Smooth lerp
followerX += (mouseX - followerX) * 0.1;
followerY += (mouseY - followerY) * 0.1;
follower.style.transform = `translate(${followerX}px, ${followerY}px)`;
requestAnimationFrame(animateFollower);
}
animateFollower();
});