-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
256 lines (220 loc) · 7.78 KB
/
script.js
File metadata and controls
256 lines (220 loc) · 7.78 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
// Enhanced Portfolio Interactions
document.addEventListener('DOMContentLoaded', function() {
// Theme toggle with smooth transition
const themeToggle = document.getElementById('themeToggle');
if (themeToggle) {
themeToggle.addEventListener('click', () => {
const current = document.documentElement.dataset.theme || 'light';
const next = current === 'dark' ? 'light' : 'dark';
document.documentElement.style.transition = 'all 0.3s ease';
document.documentElement.dataset.theme = next;
localStorage.setItem('theme', next);
setTimeout(() => {
document.documentElement.style.transition = '';
}, 300);
});
}
// Enhanced smooth scroll with offset
document.querySelectorAll('a[href^="#"]').forEach(link => {
link.addEventListener('click', e => {
e.preventDefault();
const targetId = link.getAttribute('href');
const targetElement = document.querySelector(targetId);
if (targetElement) {
const headerHeight = document.querySelector('.header').offsetHeight;
const targetPosition = targetElement.offsetTop - headerHeight - 20;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
// Enhanced typing effect with multiple texts
const typingElement = document.querySelector('.typing-text');
if (typingElement) {
const texts = ['V Priyadharshini', 'Full-Stack Developer', 'AI Enthusiast', 'Problem Solver'];
let textIndex = 0;
let charIndex = 0;
let isDeleting = false;
function typeText() {
const currentText = texts[textIndex];
if (isDeleting) {
typingElement.textContent = currentText.substring(0, charIndex - 1);
charIndex--;
} else {
typingElement.textContent = currentText.substring(0, charIndex + 1);
charIndex++;
}
let typeSpeed = isDeleting ? 50 : 100;
if (!isDeleting && charIndex === currentText.length) {
typeSpeed = 2000; // Pause at end
isDeleting = true;
} else if (isDeleting && charIndex === 0) {
isDeleting = false;
textIndex = (textIndex + 1) % texts.length;
typeSpeed = 500; // Pause before next text
}
setTimeout(typeText, typeSpeed);
}
typeText();
}
// Enhanced skill bar animations
const skillBars = document.querySelectorAll('.skill-fill');
const skillObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const width = entry.target.dataset.width;
setTimeout(() => {
entry.target.style.width = width + '%';
}, 200);
skillObserver.unobserve(entry.target);
}
});
}, { threshold: 0.5 });
skillBars.forEach(skill => {
skill.style.width = '0%';
skillObserver.observe(skill);
});
// Project card hover effects
const projectCards = document.querySelectorAll('.project-card');
projectCards.forEach(card => {
card.addEventListener('mouseenter', () => {
card.style.transform = 'translateY(-15px) rotateX(5deg)';
});
card.addEventListener('mouseleave', () => {
card.style.transform = 'translateY(0) rotateX(0deg)';
});
});
// Enhanced contact form with validation
const contactForm = document.getElementById('contactForm');
if (contactForm) {
const submitBtn = contactForm.querySelector('.submit-btn');
contactForm.addEventListener('submit', (e) => {
e.preventDefault();
// Show loading state
submitBtn.classList.add('loading');
// Get form data
const name = document.getElementById('name').value.trim();
const email = document.getElementById('email').value.trim();
const message = document.getElementById('message').value.trim();
// Validate form
if (!name || !email || !message) {
showNotification('Please fill in all fields', 'error');
submitBtn.classList.remove('loading');
return;
}
if (!isValidEmail(email)) {
showNotification('Please enter a valid email address', 'error');
submitBtn.classList.remove('loading');
return;
}
// Simulate sending (replace with actual form handling)
setTimeout(() => {
const subject = encodeURIComponent(`Portfolio Contact: ${name}`);
const body = encodeURIComponent(`${message}\n\nFrom: ${name} <${email}>`);
window.location.href = `mailto:p72981087@gmail.com?subject=${subject}&body=${body}`;
showNotification('Email client opened!', 'success');
submitBtn.classList.remove('loading');
contactForm.reset();
}, 1500);
});
}
// Floating elements animation
const floatingIcons = document.querySelectorAll('.floating-icon');
floatingIcons.forEach((icon, index) => {
icon.style.animationDelay = `${index * 0.5}s`;
});
// Parallax effect for hero section
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const hero = document.querySelector('.hero');
if (hero) {
hero.style.transform = `translateY(${scrolled * 0.5}px)`;
}
});
// Active navigation highlighting
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.nav a[href^="#"]');
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');
}
});
});
// Set current year
const yearElement = document.getElementById('year');
if (yearElement) {
yearElement.textContent = new Date().getFullYear();
}
// Add entrance animations
const animatedElements = document.querySelectorAll('.skill-card, .project-card, .contact-item');
const animationObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, { threshold: 0.1 });
animatedElements.forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(30px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
animationObserver.observe(el);
});
});
// Utility functions
function isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
function showNotification(message, type = 'info') {
const notification = document.createElement('div');
notification.className = `notification ${type}`;
notification.textContent = message;
notification.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
padding: 1rem 2rem;
border-radius: 10px;
color: white;
font-weight: 600;
z-index: 1000;
transform: translateX(100%);
transition: transform 0.3s ease;
background: ${type === 'success' ? '#22c55e' : type === 'error' ? '#ef4444' : '#007bff'};
`;
document.body.appendChild(notification);
setTimeout(() => {
notification.style.transform = 'translateX(0)';
}, 100);
setTimeout(() => {
notification.style.transform = 'translateX(100%)';
setTimeout(() => {
document.body.removeChild(notification);
}, 300);
}, 3000);
}
// Add CSS for active nav links
const style = document.createElement('style');
style.textContent = `
.nav a.active {
color: var(--accent) !important;
}
.nav a.active::after {
width: 100% !important;
}
`;
document.head.appendChild(style);