-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
373 lines (317 loc) · 11 KB
/
script.js
File metadata and controls
373 lines (317 loc) · 11 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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
// Snow Effect
function createSnowflakes() {
const snow = document.getElementById('snow');
const snowflakeCount = 30;
for (let i = 0; i < snowflakeCount; i++) {
const snowflake = document.createElement('div');
snowflake.className = 'snowflake';
snowflake.textContent = '❄';
snowflake.style.left = Math.random() * 100 + '%';
snowflake.style.animationDuration = (Math.random() * 10 + 10) + 's';
snowflake.style.animationDelay = Math.random() * 5 + 's';
snowflake.style.fontSize = (Math.random() * 10 + 10) + 'px';
snowflake.style.opacity = Math.random() * 0.6 + 0.3;
snow.appendChild(snowflake);
}
}
// Mobile Menu Toggle
function initMobileMenu() {
const hamburger = document.getElementById('hamburger');
const nav = document.getElementById('nav');
const navLinks = nav.querySelectorAll('a');
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('active');
nav.classList.toggle('active');
});
// Close menu when clicking on a link
navLinks.forEach(link => {
link.addEventListener('click', () => {
hamburger.classList.remove('active');
nav.classList.remove('active');
});
});
// Close menu when clicking outside
document.addEventListener('click', (e) => {
if (!hamburger.contains(e.target) && !nav.contains(e.target)) {
hamburger.classList.remove('active');
nav.classList.remove('active');
}
});
}
// Smooth Scrolling
function initSmoothScroll() {
const navLinks = document.querySelectorAll('nav a[href^="#"]');
navLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const targetId = link.getAttribute('href');
const targetSection = document.querySelector(targetId);
if (targetSection) {
targetSection.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
}
// Skill Bar Animation
function animateSkillBars() {
const skillBars = document.querySelectorAll('.skill-progress');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const progress = entry.target.getAttribute('data-progress');
entry.target.style.width = progress + '%';
entry.target.classList.add('animate');
observer.unobserve(entry.target);
}
});
}, {
threshold: 0.5
});
skillBars.forEach(bar => {
observer.observe(bar);
});
}
// Modal Functionality
function initModals() {
const clickableCards = document.querySelectorAll('.clickable-card');
const modals = document.querySelectorAll('.modal');
const closeButtons = document.querySelectorAll('.modal-close');
// Open modal
clickableCards.forEach(card => {
card.addEventListener('click', () => {
const modalId = card.getAttribute('data-modal');
const modal = document.getElementById(modalId);
if (modal) {
modal.classList.add('active');
document.body.classList.add('modal-open');
}
});
});
// Close modal with close button
closeButtons.forEach(button => {
button.addEventListener('click', () => {
const modal = button.closest('.modal');
if (modal) {
modal.classList.remove('active');
document.body.classList.remove('modal-open');
}
});
});
// Close modal when clicking outside
modals.forEach(modal => {
modal.addEventListener('click', (e) => {
if (e.target === modal) {
modal.classList.remove('active');
document.body.classList.remove('modal-open');
}
});
});
// Close modal with Escape key
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
modals.forEach(modal => {
if (modal.classList.contains('active')) {
modal.classList.remove('active');
document.body.classList.remove('modal-open');
}
});
}
});
}
// Active Nav Link on Scroll
function initActiveNavLink() {
const sections = document.querySelectorAll('section');
const navLinks = document.querySelectorAll('nav a');
window.addEventListener('scroll', () => {
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (window.pageYOffset >= sectionTop - 200) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${current}`) {
link.classList.add('active');
}
});
});
}
// Contact Button Scroll
function initContactButton() {
const contactButton = document.getElementById('learnMoreBtn');
if (contactButton) {
contactButton.addEventListener('click', (e) => {
e.preventDefault();
const contactSection = document.getElementById('skills');
if (contactSection) {
contactSection.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
}
}
// Card Hover Effect Enhancement
function initCardEffects() {
const cards = document.querySelectorAll('.card');
cards.forEach(card => {
card.addEventListener('mouseenter', function() {
this.style.boxShadow = '0 8px 24px rgba(114, 192, 44, 0.2)';
});
card.addEventListener('mouseleave', function() {
this.style.boxShadow = 'none';
});
});
}
// Lazy Load Images
function initLazyLoad() {
const images = document.querySelectorAll('img[src]');
const imageObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.style.opacity = '0';
img.style.transition = 'opacity 0.5s ease';
img.onload = () => {
img.style.opacity = '1';
};
observer.unobserve(img);
}
});
});
images.forEach(img => {
imageObserver.observe(img);
});
}
// Parallax Effect for Hero
function initParallax() {
const hero = document.getElementById('hero');
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const heroContent = hero.querySelector('.hero-content');
if (heroContent && scrolled < window.innerHeight) {
heroContent.style.transform = `translateY(${scrolled * 0.5}px)`;
heroContent.style.opacity = 1 - (scrolled / window.innerHeight);
}
});
}
// Typing Effect for Hero Description (Optional Enhancement)
function initTypingEffect() {
const heroDesc = document.querySelector('.hero-desc');
if (!heroDesc) return;
const text = heroDesc.textContent;
heroDesc.textContent = '';
heroDesc.style.borderRight = '2px solid var(--accent)';
let index = 0;
const typeSpeed = 50;
function type() {
if (index < text.length) {
heroDesc.textContent += text.charAt(index);
index++;
setTimeout(type, typeSpeed);
} else {
setTimeout(() => {
heroDesc.style.borderRight = 'none';
}, 500);
}
}
// Start typing after a short delay
setTimeout(type, 500);
}
// Section Fade In on Scroll
function initSectionFadeIn() {
const sections = document.querySelectorAll('section');
const sectionObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, {
threshold: 0.1
});
sections.forEach(section => {
section.style.opacity = '0';
section.style.transform = 'translateY(20px)';
section.style.transition = 'opacity 0.8s ease, transform 0.8s ease';
sectionObserver.observe(section);
});
}
// Header Background on Scroll
function initHeaderScroll() {
const header = document.querySelector('header');
window.addEventListener('scroll', () => {
if (window.pageYOffset > 100) {
header.style.background = 'rgba(10, 10, 10, 0.98)';
header.style.boxShadow = '0 2px 10px rgba(114, 192, 44, 0.1)';
} else {
header.style.background = 'rgba(10, 10, 10, 0.95)';
header.style.boxShadow = 'none';
}
});
}
// Add Hover Effect to Social Icons
function initSocialIconEffects() {
const socialIcons = document.querySelectorAll('.icon');
socialIcons.forEach(icon => {
icon.addEventListener('mouseenter', function() {
this.style.transform = 'scale(1.1) rotate(5deg)';
});
icon.addEventListener('mouseleave', function() {
this.style.transform = 'scale(1) rotate(0deg)';
});
});
}
// Initialize all functions when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
createSnowflakes();
initMobileMenu();
initSmoothScroll();
animateSkillBars();
initModals();
initActiveNavLink();
initContactButton();
initCardEffects();
initLazyLoad();
initParallax();
initSectionFadeIn();
initHeaderScroll();
initSocialIconEffects();
// Optional: Uncomment to enable typing effect
// initTypingEffect();
});
// Add resize event listener for responsive adjustments
window.addEventListener('resize', () => {
// Close mobile menu on resize to desktop
if (window.innerWidth > 768) {
const hamburger = document.getElementById('hamburger');
const nav = document.getElementById('nav');
hamburger.classList.remove('active');
nav.classList.remove('active');
}
});
// Performance optimization: Debounce scroll events
function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
// Apply debounce to scroll-heavy functions
const debouncedScroll = debounce(() => {
// Any additional scroll-based animations can go here
}, 10);
window.addEventListener('scroll', debouncedScroll);