-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
352 lines (287 loc) · 9.72 KB
/
script.js
File metadata and controls
352 lines (287 loc) · 9.72 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
// ===============================
// Mobile Navigation Toggle
// ===============================
const hamburger = document.getElementById('hamburger');
const navMenu = document.getElementById('navMenu');
if (hamburger && navMenu) {
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('active');
navMenu.classList.toggle('active');
});
// Close menu when clicking nav links
const navLinks = navMenu.querySelectorAll('a');
navLinks.forEach(link => {
link.addEventListener('click', () => {
hamburger.classList.remove('active');
navMenu.classList.remove('active');
});
});
}
// ===============================
// Scroll Animations
// ===============================
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry, index) => {
if (entry.isIntersecting) {
// Add stagger delay
setTimeout(() => {
entry.target.classList.add('animate-in');
}, index * 100);
observer.unobserve(entry.target);
}
});
}, observerOptions);
// Observe all elements with animate-on-scroll class
const animatedElements = document.querySelectorAll('.animate-on-scroll');
animatedElements.forEach(el => observer.observe(el));
// ===============================
// Smooth Scroll for Navigation
// ===============================
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const offset = 80; // Account for fixed nav
const targetPosition = target.offsetTop - offset;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
// ===============================
// Hero Canvas Animation (Grid/Particles)
// ===============================
const canvas = document.getElementById('heroCanvas');
if (canvas) {
const ctx = canvas.getContext('2d');
// Set canvas size
function resizeCanvas() {
canvas.width = canvas.offsetWidth;
canvas.height = canvas.offsetHeight;
}
resizeCanvas();
window.addEventListener('resize', resizeCanvas);
// Grid configuration
const grid = {
rows: 20,
cols: 20,
spacing: 0
};
// Calculate spacing
function calculateGrid() {
grid.spacing = Math.min(canvas.width / grid.cols, canvas.height / grid.rows);
}
calculateGrid();
window.addEventListener('resize', calculateGrid);
// Particles
const particles = [];
const particleCount = 50;
class Particle {
constructor() {
this.reset();
}
reset() {
this.x = Math.random() * canvas.width;
this.y = Math.random() * canvas.height;
this.vx = (Math.random() - 0.5) * 0.5;
this.vy = (Math.random() - 0.5) * 0.5;
this.radius = Math.random() * 2 + 1;
this.opacity = Math.random() * 0.5 + 0.2;
}
update() {
this.x += this.vx;
this.y += this.vy;
// Wrap around edges
if (this.x < 0) this.x = canvas.width;
if (this.x > canvas.width) this.x = 0;
if (this.y < 0) this.y = canvas.height;
if (this.y > canvas.height) this.y = 0;
}
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);
ctx.fillStyle = `rgba(60, 79, 255, ${this.opacity})`;
ctx.fill();
}
}
// Create particles
for (let i = 0; i < particleCount; i++) {
particles.push(new Particle());
}
// Animation loop
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw grid
ctx.strokeStyle = 'rgba(220, 220, 239, 0.05)';
ctx.lineWidth = 1;
// Vertical lines
for (let i = 0; i <= grid.cols; i++) {
const x = i * grid.spacing;
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, canvas.height);
ctx.stroke();
}
// Horizontal lines
for (let i = 0; i <= grid.rows; i++) {
const y = i * grid.spacing;
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(canvas.width, y);
ctx.stroke();
}
// Update and draw particles
particles.forEach(particle => {
particle.update();
particle.draw();
});
// Draw connections
ctx.strokeStyle = 'rgba(60, 79, 255, 0.1)';
ctx.lineWidth = 0.5;
for (let i = 0; i < particles.length; i++) {
for (let j = i + 1; j < particles.length; j++) {
const dx = particles[i].x - particles[j].x;
const dy = particles[i].y - particles[j].y;
const distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 100) {
ctx.beginPath();
ctx.moveTo(particles[i].x, particles[i].y);
ctx.lineTo(particles[j].x, particles[j].y);
ctx.stroke();
}
}
}
requestAnimationFrame(animate);
}
animate();
}
// ===============================
// Contact Form Handling
// ===============================
const contactForm = document.getElementById('contactForm');
if (contactForm) {
contactForm.addEventListener('submit', (e) => {
e.preventDefault();
// Get form data
const formData = new FormData(contactForm);
const data = Object.fromEntries(formData);
console.log('Form submitted:', data);
// Show success message (in real app, send to backend)
alert('Thank you for your message! We will get back to you soon.');
contactForm.reset();
});
}
// ===============================
// Navigation Scroll Effect
// ===============================
let lastScroll = 0;
const nav = document.querySelector('.nav');
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
if (currentScroll > 100) {
nav.style.background = 'rgba(23, 25, 70, 0.95)';
nav.style.boxShadow = '0 4px 20px rgba(0, 0, 0, 0.3)';
} else {
nav.style.background = 'rgba(23, 25, 70, 0.8)';
nav.style.boxShadow = 'none';
}
lastScroll = currentScroll;
});
// ===============================
// Parallax Effect
// ===============================
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const parallaxElements = document.querySelectorAll('.hero-bg-glow, .section-glow');
parallaxElements.forEach(el => {
const speed = 0.5;
el.style.transform = `translateX(-50%) translateY(${scrolled * speed}px)`;
});
});
// ===============================
// Initialize on Load
// ===============================
document.addEventListener('DOMContentLoaded', () => {
console.log('Portfolio loaded successfully!');
// Add entrance animation to hero
setTimeout(() => {
document.querySelector('.hero-container')?.classList.add('loaded');
}, 100);
});
// ===============================
// Project Stack Logic
// ===============================
function initProjectStack() {
const stackCards = document.querySelectorAll('.stack-card');
const paginationDots = document.querySelectorAll('.pagination-dot');
const wrapper = document.querySelector('.project-stack-wrapper');
let currentStackIndex = 0;
let autoRotateInterval;
if (!stackCards.length) return;
function updateStack(index) {
stackCards.forEach((card, i) => {
card.classList.remove('active', 'behind-1', 'behind-2');
if (i === index) {
card.classList.add('active');
} else if (i === (index + 1) % stackCards.length) {
card.classList.add('behind-1');
} else if (i === (index + 2) % stackCards.length) {
card.classList.add('behind-2');
}
});
paginationDots.forEach((dot, i) => {
dot.classList.toggle('active', i === index);
});
currentStackIndex = index;
}
function startAutoRotate() {
autoRotateInterval = setInterval(() => {
const nextIndex = (currentStackIndex + 1) % stackCards.length;
updateStack(nextIndex);
}, 8000);
}
function resetAutoRotate() {
clearInterval(autoRotateInterval);
startAutoRotate();
}
// Initial State
updateStack(0);
startAutoRotate();
// Event Listeners
stackCards.forEach((card, index) => {
card.addEventListener('click', () => {
if (!card.classList.contains('active')) {
updateStack(index);
resetAutoRotate();
}
});
});
paginationDots.forEach((dot, index) => {
dot.addEventListener('click', (e) => {
e.stopPropagation();
updateStack(index);
resetAutoRotate();
});
});
if (wrapper) {
wrapper.addEventListener('mouseenter', () => clearInterval(autoRotateInterval));
wrapper.addEventListener('mouseleave', () => startAutoRotate());
}
}
// ===============================
// Initialize on Load
// ===============================
document.addEventListener('DOMContentLoaded', () => {
initProjectStack();
// Add entrance animation to hero
setTimeout(() => {
document.querySelector('.hero-container')?.classList.add('loaded');
}, 100);
});