-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
327 lines (275 loc) · 12 KB
/
Copy pathscript.js
File metadata and controls
327 lines (275 loc) · 12 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
/* ============================================================
SIDHARTH DUBEY — PORTFOLIO JAVASCRIPT
============================================================ */
document.addEventListener('DOMContentLoaded', () => {
// ─── Loader ──────────────────────────────
const loader = document.getElementById('loader');
window.addEventListener('load', () => {
setTimeout(() => {
loader.classList.add('hidden');
}, 800);
});
// Fallback in case load already fired
if (document.readyState === 'complete') {
setTimeout(() => {
loader.classList.add('hidden');
}, 800);
}
// ─── Cursor Glow ────────────────────────────
const cursorGlow = document.getElementById('cursorGlow');
if (window.innerWidth > 768) {
let glowVisible = false;
document.addEventListener('mousemove', (e) => {
if (!glowVisible) {
cursorGlow.style.opacity = '1';
glowVisible = true;
}
requestAnimationFrame(() => {
cursorGlow.style.left = e.clientX + 'px';
cursorGlow.style.top = e.clientY + 'px';
});
});
}
// ─── Navbar scroll ──────────────────────────
const navbar = document.getElementById('navbar');
const backToTop = document.getElementById('backToTop');
let lastScroll = 0;
window.addEventListener('scroll', () => {
const currentScroll = window.scrollY;
if (currentScroll > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
// Back to top visibility
if (currentScroll > 500) {
backToTop.classList.add('visible');
} else {
backToTop.classList.remove('visible');
}
lastScroll = currentScroll;
});
backToTop.addEventListener('click', () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
// ─── Mobile Menu ────────────────────────────
const hamburger = document.getElementById('hamburger');
const navLinks = document.getElementById('navLinks');
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('active');
navLinks.classList.toggle('active');
document.body.style.overflow = navLinks.classList.contains('active') ? 'hidden' : '';
});
// Close menu on link click
document.querySelectorAll('.nav-link').forEach(link => {
link.addEventListener('click', () => {
hamburger.classList.remove('active');
navLinks.classList.remove('active');
document.body.style.overflow = '';
});
});
// ─── Active Nav Link on Scroll ─────────────
const sections = document.querySelectorAll('section[id]');
const navLinkEls = document.querySelectorAll('.nav-link');
const observerNav = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const id = entry.target.id;
navLinkEls.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${id}`) {
link.classList.add('active');
}
});
}
});
}, {
rootMargin: '-30% 0px -70% 0px'
});
sections.forEach(section => observerNav.observe(section));
// ─── Theme Toggle ───────────────────────────
const themeToggle = document.getElementById('themeToggle');
const themeIcon = document.getElementById('themeIcon');
const html = document.documentElement;
// Check saved preference
const savedTheme = localStorage.getItem('theme');
if (savedTheme) {
html.setAttribute('data-theme', savedTheme);
themeIcon.className = savedTheme === 'light' ? 'fas fa-sun' : 'fas fa-moon';
}
themeToggle.addEventListener('click', () => {
const currentTheme = html.getAttribute('data-theme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
html.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
themeIcon.className = newTheme === 'light' ? 'fas fa-sun' : 'fas fa-moon';
});
// ─── Scroll Animations ──────────────────────
const animatedElements = document.querySelectorAll('[data-animate]');
const animateObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const delay = entry.target.getAttribute('data-delay') || 0;
setTimeout(() => {
entry.target.classList.add('animated');
}, parseInt(delay));
animateObserver.unobserve(entry.target);
}
});
}, {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
});
animatedElements.forEach(el => animateObserver.observe(el));
// ─── Counter Animation ──────────────────────
const counters = document.querySelectorAll('[data-count]');
const counterObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const target = parseInt(entry.target.getAttribute('data-count'));
let current = 0;
const increment = target / 50;
const duration = 1500;
const stepTime = duration / 50;
const timer = setInterval(() => {
current += increment;
if (current >= target) {
entry.target.textContent = target;
clearInterval(timer);
} else {
entry.target.textContent = Math.floor(current);
}
}, stepTime);
counterObserver.unobserve(entry.target);
}
});
}, { threshold: 0.5 });
counters.forEach(counter => counterObserver.observe(counter));
// ─── Project Filters ────────────────────────
const filterBtns = document.querySelectorAll('.filter-btn');
const projectCards = document.querySelectorAll('.project-card');
filterBtns.forEach(btn => {
btn.addEventListener('click', () => {
// Active state
filterBtns.forEach(b => b.classList.remove('active'));
btn.classList.add('active');
const filter = btn.getAttribute('data-filter');
projectCards.forEach(card => {
if (filter === 'all' || card.getAttribute('data-category') === filter) {
card.classList.remove('hidden');
card.style.animation = 'fadeInUp 0.4s ease forwards';
} else {
card.classList.add('hidden');
}
});
});
});
// ─── Contact Form ───────────────────────────
const contactForm = document.getElementById('contactForm');
const submitBtn = document.getElementById('submitBtn');
contactForm.addEventListener('submit', (e) => {
e.preventDefault();
// Simple animation feedback
const originalHTML = submitBtn.innerHTML;
submitBtn.innerHTML = '<span>Sending...</span><i class="fas fa-spinner fa-spin"></i>';
submitBtn.disabled = true;
setTimeout(() => {
submitBtn.innerHTML = '<span>Message Sent!</span><i class="fas fa-check"></i>';
submitBtn.style.background = 'linear-gradient(135deg, #00d4aa 0%, #00b894 100%)';
setTimeout(() => {
submitBtn.innerHTML = originalHTML;
submitBtn.style.background = '';
submitBtn.disabled = false;
contactForm.reset();
}, 2500);
}, 1500);
});
// ─── Smooth Reveal for child elements ───────
// Add stagger animation to grid children
const staggerGrids = document.querySelectorAll('.skills-grid, .tools-grid, .logos-grid, .clients-grid');
const staggerObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const children = entry.target.children;
Array.from(children).forEach((child, index) => {
child.style.opacity = '0';
child.style.transform = 'translateY(20px)';
child.style.transition = `opacity 0.5s ease ${index * 0.08}s, transform 0.5s ease ${index * 0.08}s`;
setTimeout(() => {
child.style.opacity = '1';
child.style.transform = 'translateY(0)';
}, 50);
});
staggerObserver.unobserve(entry.target);
}
});
}, { threshold: 0.2 });
staggerGrids.forEach(grid => staggerObserver.observe(grid));
// ─── Tilt effect on project cards ───────────
if (window.innerWidth > 768) {
const tiltCards = document.querySelectorAll('.project-card, .logo-card');
tiltCards.forEach(card => {
card.addEventListener('mousemove', (e) => {
const rect = card.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const centerX = rect.width / 2;
const centerY = rect.height / 2;
const rotateX = (y - centerY) / 20;
const rotateY = (centerX - x) / 20;
card.style.transform = `perspective(1000px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) translateY(-6px)`;
});
card.addEventListener('mouseleave', () => {
card.style.transform = '';
});
});
}
// ─── Typing effect for hero badge ───────────
const badge = document.querySelector('.hero-badge');
if (badge) {
const roles = ['Available for freelance work', 'Open to collaborations', 'Let\'s create something amazing'];
let roleIndex = 0;
let charIndex = 0;
let isDeleting = false;
const badgeDot = badge.querySelector('.badge-dot');
function typeRole() {
const currentRole = roles[roleIndex];
if (isDeleting) {
badge.textContent = currentRole.substring(0, charIndex - 1);
charIndex--;
} else {
badge.textContent = currentRole.substring(0, charIndex + 1);
charIndex++;
}
// Re-prepend the dot
badge.prepend(badgeDot);
let typeSpeed = isDeleting ? 30 : 60;
if (!isDeleting && charIndex === currentRole.length) {
typeSpeed = 2500;
isDeleting = true;
} else if (isDeleting && charIndex === 0) {
isDeleting = false;
roleIndex = (roleIndex + 1) % roles.length;
typeSpeed = 400;
}
setTimeout(typeRole, typeSpeed);
}
// Start after initial animation
setTimeout(typeRole, 3000);
}
});
// ─── Fade-in animation keyframe (used in JS) ────
const style = document.createElement('style');
style.textContent = `
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
`;
document.head.appendChild(style);