Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
430 lines (364 loc) · 12.7 KB
/
Copy pathscript.js
File metadata and controls
430 lines (364 loc) · 12.7 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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
// DOM Elements
const themeToggle = document.querySelector('.theme-toggle');
const hamburger = document.querySelector('.hamburger');
const nav = document.querySelector('.nav');
const navLinks = document.querySelectorAll('.nav-link');
const contactForm = document.getElementById('contactForm');
const downloadResumeBtn = document.getElementById('downloadResume');
// Typing Animation
class TypingAnimation {
constructor(element, words, speed = 100) {
this.element = element;
this.words = words;
this.speed = speed;
this.currentWordIndex = 0;
this.currentCharIndex = 0;
this.isDeleting = false;
this.init();
}
init() {
this.type();
}
type() {
const currentWord = this.words[this.currentWordIndex];
if (this.isDeleting) {
this.element.textContent = currentWord.substring(0, this.currentCharIndex - 1);
this.currentCharIndex--;
} else {
this.element.textContent = currentWord.substring(0, this.currentCharIndex + 1);
this.currentCharIndex++;
}
let typeSpeed = this.speed;
if (this.isDeleting) {
typeSpeed /= 2;
}
if (!this.isDeleting && this.currentCharIndex === currentWord.length) {
typeSpeed = 2000; // Pause at end
this.isDeleting = true;
} else if (this.isDeleting && this.currentCharIndex === 0) {
this.isDeleting = false;
this.currentWordIndex = (this.currentWordIndex + 1) % this.words.length;
typeSpeed = 500; // Pause before typing next word
}
setTimeout(() => this.type(), typeSpeed);
}
}
// Theme Toggle Functionality
function initThemeToggle() {
const savedTheme = localStorage.getItem('theme') || 'light';
document.documentElement.setAttribute('data-theme', savedTheme);
updateThemeIcon(savedTheme);
themeToggle.addEventListener('click', () => {
const currentTheme = document.documentElement.getAttribute('data-theme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
document.documentElement.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
updateThemeIcon(newTheme);
// Update header background when theme changes
updateHeaderBackground(newTheme);
});
}
// Update header background based on theme
function updateHeaderBackground(theme) {
const header = document.querySelector('.header');
if (theme === 'dark') {
header.style.background = 'rgba(15, 23, 42, 0.95)';
} else {
header.style.background = 'rgba(255, 255, 255, 0.95)';
}
}
function updateThemeIcon(theme) {
const icon = themeToggle.querySelector('i');
if (theme === 'dark') {
icon.className = 'fas fa-sun';
} else {
icon.className = 'fas fa-moon';
}
}
// Mobile Menu Toggle
function initMobileMenu() {
hamburger.addEventListener('click', () => {
nav.classList.toggle('active');
hamburger.classList.toggle('active');
});
// Close mobile menu when clicking on nav links
navLinks.forEach(link => {
link.addEventListener('click', () => {
nav.classList.remove('active');
hamburger.classList.remove('active');
});
});
}
// Smooth Scrolling for Navigation Links
function initSmoothScrolling() {
navLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const targetId = link.getAttribute('href');
const targetSection = document.querySelector(targetId);
if (targetSection) {
const headerHeight = document.querySelector('.header').offsetHeight;
const targetPosition = targetSection.offsetTop - headerHeight;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
}
// Scroll Animations
function initScrollAnimations() {
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
}
});
}, observerOptions);
// Add fade-in class to elements and observe them
const animateElements = document.querySelectorAll('.about-content, .skills-category, .project-card, .contact-content');
animateElements.forEach(el => {
el.classList.add('fade-in');
observer.observe(el);
});
}
// Active Navigation Link Highlighting
function initActiveNavHighlighting() {
const sections = document.querySelectorAll('section[id]');
window.addEventListener('scroll', () => {
const scrollPos = window.scrollY + 100;
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.offsetHeight;
const sectionId = section.getAttribute('id');
if (scrollPos >= sectionTop && scrollPos < sectionTop + sectionHeight) {
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${sectionId}`) {
link.classList.add('active');
}
});
}
});
});
}
// Form Validation and Submission
function initContactForm() {
contactForm.addEventListener('submit', (e) => {
e.preventDefault();
// Get form data
const formData = new FormData(contactForm);
const name = formData.get('name').trim();
const email = formData.get('email').trim();
const subject = formData.get('subject').trim();
const message = formData.get('message').trim();
// Validation
if (!name || !email || !subject || !message) {
showFormMessage('Please fill in all fields.', 'error');
return;
}
if (!isValidEmail(email)) {
showFormMessage('Please enter a valid email address.', 'error');
return;
}
// Simulate form submission
showFormMessage('Sending message...', 'info');
setTimeout(() => {
showFormMessage('Thank you! Your message has been sent successfully.', 'success');
contactForm.reset();
}, 2000);
});
}
function isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
function showFormMessage(message, type) {
// Remove existing messages
const existingMessage = contactForm.querySelector('.form-message');
if (existingMessage) {
existingMessage.remove();
}
// Create new message
const messageDiv = document.createElement('div');
messageDiv.className = `form-message ${type}`;
messageDiv.textContent = message;
// Add styles based on type
switch (type) {
case 'success':
messageDiv.style.background = '#10b981';
messageDiv.style.color = 'white';
break;
case 'error':
messageDiv.style.background = '#ef4444';
messageDiv.style.color = 'white';
break;
case 'info':
messageDiv.style.background = '#3b82f6';
messageDiv.style.color = 'white';
break;
}
messageDiv.style.padding = '1rem';
messageDiv.style.borderRadius = '8px';
messageDiv.style.marginTop = '1rem';
messageDiv.style.textAlign = 'center';
contactForm.appendChild(messageDiv);
// Auto-remove success/info messages after 5 seconds
if (type === 'success' || type === 'info') {
setTimeout(() => {
messageDiv.remove();
}, 5000);
}
}
// Download Resume Functionality
function initDownloadResume() {
downloadResumeBtn.addEventListener('click', (e) => {
e.preventDefault();
// Create a temporary link to trigger download
const link = document.createElement('a');
link.href = '#'; // Replace with actual resume URL when available
link.download = 'Sasank_Reddy_Resume.pdf';
link.textContent = 'Download Resume';
// Show message that resume will be available soon
showFormMessage('Resume download will be available soon!', 'info');
});
}
// Header Scroll Effect
function initHeaderScrollEffect() {
const header = document.querySelector('.header');
window.addEventListener('scroll', () => {
const currentTheme = document.documentElement.getAttribute('data-theme');
if (window.scrollY > 100) {
if (currentTheme === 'dark') {
header.style.background = 'rgba(15, 23, 42, 0.98)';
header.style.boxShadow = '0 2px 20px rgba(0, 0, 0, 0.3)';
} else {
header.style.background = 'rgba(255, 255, 255, 0.98)';
header.style.boxShadow = '0 2px 20px rgba(0, 0, 0, 0.1)';
}
} else {
if (currentTheme === 'dark') {
header.style.background = 'rgba(15, 23, 42, 0.95)';
header.style.boxShadow = 'none';
} else {
header.style.background = 'rgba(255, 255, 255, 0.95)';
header.style.boxShadow = 'none';
}
}
});
}
// Project Card Hover Effects
function initProjectCardEffects() {
const projectCards = document.querySelectorAll('.project-card');
projectCards.forEach(card => {
card.addEventListener('mouseenter', () => {
card.style.transform = 'translateY(-10px) scale(1.02)';
});
card.addEventListener('mouseleave', () => {
card.style.transform = 'translateY(0) scale(1)';
});
});
}
// Skills Animation
function initSkillsAnimation() {
const skillItems = document.querySelectorAll('.skill-item');
skillItems.forEach((item, index) => {
item.style.animationDelay = `${index * 0.1}s`;
item.classList.add('animate-skill');
});
}
// Add CSS for skill animation
const style = document.createElement('style');
style.textContent = `
.animate-skill {
animation: skillFadeIn 0.6s ease forwards;
opacity: 0;
transform: translateY(20px);
}
@keyframes skillFadeIn {
to {
opacity: 1;
transform: translateY(0);
}
}
.nav.active {
display: block;
position: absolute;
top: 100%;
left: 0;
right: 0;
background: var(--bg-primary);
border-top: 1px solid var(--border-color);
box-shadow: var(--shadow-medium);
}
.nav.active .nav-list {
flex-direction: column;
padding: 1rem;
gap: 1rem;
}
.hamburger.active span:nth-child(1) {
transform: rotate(45deg) translate(5px, 5px);
}
.hamburger.active span:nth-child(2) {
opacity: 0;
}
.hamburger.active span:nth-child(3) {
transform: rotate(-45deg) translate(7px, -6px);
}
.nav-link.active {
color: var(--primary-color);
}
.nav-link.active::after {
width: 100%;
}
`;
document.head.appendChild(style);
// Initialize all functionality when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
// Initialize typing animation
const typedElement = document.querySelector('.typed-text');
if (typedElement) {
new TypingAnimation(typedElement, [
'Frontend Developer',
'Competitive Programmer',
'IT Undergraduate',
'Problem Solver'
], 100);
}
// Initialize all other functionality
initThemeToggle();
initMobileMenu();
initSmoothScrolling();
initScrollAnimations();
initActiveNavHighlighting();
initContactForm();
initDownloadResume();
initHeaderScrollEffect();
initProjectCardEffects();
initSkillsAnimation();
// Set initial header background based on saved theme
const savedTheme = localStorage.getItem('theme') || 'light';
updateHeaderBackground(savedTheme);
console.log('Portfolio website initialized successfully!');
});
// Add loading animation
window.addEventListener('load', () => {
document.body.classList.add('loaded');
});
// Add CSS for loading animation
const loadingStyle = document.createElement('style');
loadingStyle.textContent = `
body {
opacity: 0;
transition: opacity 0.5s ease;
}
body.loaded {
opacity: 1;
}
`;
document.head.appendChild(loadingStyle);