Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
276 lines (230 loc) · 8.62 KB
/
Copy pathscript.js
File metadata and controls
276 lines (230 loc) · 8.62 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
/**
* Main JavaScript file for Reena's Portfolio
* Handles navigation, animations, and interactive elements
*/
// DOM Elements
const hamburger = document.querySelector('.hamburger');
const navLinks = document.querySelector('.nav-links');
const header = document.querySelector('header');
const sections = document.querySelectorAll('section');
const projectCards = document.querySelectorAll('.project-card');
const techCards = document.querySelectorAll('.tech-card');
const serviceCards = document.querySelectorAll('.service-card');
// Make all sections visible immediately
document.addEventListener('DOMContentLoaded', () => {
sections.forEach(section => {
section.classList.add('section-visible');
});
// Initialize tech level bars
initTechLevels();
// Initialize form validation
initContactForm();
});
// Mobile Navigation Toggle
hamburger.addEventListener('click', () => {
navLinks.classList.toggle('open');
hamburger.classList.toggle('active');
});
// Close mobile menu when a link is clicked
document.querySelectorAll('.nav-links a').forEach(link => {
link.addEventListener('click', () => {
if (navLinks.classList.contains('open')) {
navLinks.classList.remove('open');
hamburger.classList.remove('active');
}
});
});
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
const targetId = this.getAttribute('href');
// Skip if it's just "#" or external link
if (targetId === '#' || !targetId.startsWith('#')) return;
e.preventDefault();
const targetElement = document.querySelector(targetId);
if (targetElement) {
window.scrollTo({
top: targetElement.offsetTop - 80, // Offset for header
behavior: 'smooth'
});
}
});
});
// Function to scroll to a section (used by buttons)
function scrollToSection(sectionId) {
const section = document.getElementById(sectionId);
if (section) {
window.scrollTo({
top: section.offsetTop - 80, // Offset for header
behavior: 'smooth'
});
}
}
// Header scroll effect
window.addEventListener('scroll', () => {
if (window.scrollY > 100) {
header.classList.add('scrolled');
} else {
header.classList.remove('scrolled');
}
// Animate elements on scroll
animateOnScroll();
});
// Active navigation link based on scroll position
window.addEventListener('scroll', () => {
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (window.scrollY >= sectionTop - 200) {
current = section.getAttribute('id');
}
});
document.querySelectorAll('.nav-links a').forEach(link => {
link.classList.remove('active');
const href = link.getAttribute('href');
if (href && href.includes('#' + current)) {
link.classList.add('active');
}
});
});
// Initialize technology level bars
function initTechLevels() {
document.querySelectorAll('.tech-level-bar').forEach(bar => {
const level = bar.getAttribute('data-level') || 0;
bar.style.width = `${level}%`;
});
}
// Animate elements when they come into view
function animateOnScroll() {
const triggerBottom = window.innerHeight * 0.8;
[projectCards, techCards, serviceCards].forEach(cards => {
cards.forEach(card => {
const cardTop = card.getBoundingClientRect().top;
if (cardTop < triggerBottom) {
card.classList.add('visible');
}
});
});
}
// Contact form validation and submission
function initContactForm() {
const contactForm = document.getElementById('contactForm');
const formStatus = document.getElementById('form-status');
if (!contactForm) return;
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
// Basic validation
const name = document.getElementById('name');
const email = document.getElementById('email');
const subject = document.getElementById('subject');
const message = document.getElementById('message');
let isValid = true;
if (!name.value.trim()) {
highlightError(name);
isValid = false;
} else {
removeError(name);
}
if (!email.value.trim() || !isValidEmail(email.value)) {
highlightError(email);
isValid = false;
} else {
removeError(email);
}
if (!subject.value.trim()) {
highlightError(subject);
isValid = false;
} else {
removeError(subject);
}
if (!message.value.trim()) {
highlightError(message);
isValid = false;
} else {
removeError(message);
}
if (isValid) {
// Show loading status
formStatus.innerHTML = '<p class="sending">Sending message...</p>';
// Disable the submit button during submission
const submitButton = contactForm.querySelector('.submit-button');
submitButton.disabled = true;
// Get form data
const formData = new FormData(contactForm);
// Send the form data to Formspree
fetch(contactForm.action, {
method: 'POST',
body: formData,
headers: {
'Accept': 'application/json'
}
})
.then(response => {
if (response.ok) {
return response.json();
} else {
throw new Error('Form submission failed');
}
})
.then(data => {
// Show success message
formStatus.innerHTML = '<p class="success-message">Thank you! Your message has been sent.</p>';
// Reset the form
contactForm.reset();
// Re-enable the submit button
submitButton.disabled = false;
// Clear the success message after 5 seconds
setTimeout(function() {
formStatus.innerHTML = '';
}, 5000);
})
.catch(error => {
console.error('Error:', error);
// Show error message
formStatus.innerHTML = '<p class="error-message">Sorry, there was a problem sending your message. Please email me directly at reenabharath1581@gmail.com</p>';
// Re-enable the submit button
submitButton.disabled = false;
});
}
});
}
// Helper functions for form validation
function highlightError(element) {
element.classList.add('error');
element.parentElement.classList.add('error-group');
}
function removeError(element) {
element.classList.remove('error');
element.parentElement.classList.remove('error-group');
}
function isValidEmail(email) {
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
// Project filter functionality
const filterButtons = document.querySelectorAll('.filter-btn');
if (filterButtons.length > 0) {
filterButtons.forEach(button => {
button.addEventListener('click', () => {
// Remove active class from all buttons
filterButtons.forEach(btn => btn.classList.remove('active'));
// Add active class to clicked button
button.classList.add('active');
// Get filter value
const filterValue = button.getAttribute('data-filter');
// Filter projects
document.querySelectorAll('.project-card').forEach(project => {
if (filterValue === 'all') {
project.style.display = 'block';
} else {
if (project.classList.contains(filterValue)) {
project.style.display = 'block';
} else {
project.style.display = 'none';
}
}
});
});
});
}