-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
203 lines (181 loc) · 6.67 KB
/
script.js
File metadata and controls
203 lines (181 loc) · 6.67 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
// Portfolio Filter Functionality
function initPortfolioFilter() {
const filterBtns = document.querySelectorAll('.filter-btn');
const portfolioItems = document.querySelectorAll('.portfolio-item');
filterBtns.forEach(btn => {
btn.addEventListener('click', () => {
// Remove active class from all buttons
filterBtns.forEach(b => b.classList.remove('active'));
// Add active class to clicked button
btn.classList.add('active');
const filter = btn.getAttribute('data-filter');
portfolioItems.forEach(item => {
if (filter === 'all') {
item.style.display = 'block';
setTimeout(() => {
item.style.opacity = '1';
item.style.transform = 'scale(1)';
}, 50);
} else {
const category = item.getAttribute('data-category');
if (category === filter) {
item.style.display = 'block';
setTimeout(() => {
item.style.opacity = '1';
item.style.transform = 'scale(1)';
}, 50);
} else {
item.style.opacity = '0';
item.style.transform = 'scale(0.8)';
setTimeout(() => {
item.style.display = 'none';
}, 300);
}
}
});
});
});
}
// Formspree Form Handling
function handleContactForm() {
const form = document.querySelector('.contact-form');
const submitBtn = form.querySelector('button[type="submit"]');
const btnText = submitBtn.querySelector('.btn-text');
const btnLoading = submitBtn.querySelector('.btn-loading');
form.addEventListener('submit', function(e) {
e.preventDefault();
// Show loading state
btnText.style.display = 'none';
btnLoading.style.display = 'block';
submitBtn.disabled = true;
// Get form data
const formData = new FormData(form);
// Send to Formspree
fetch(form.action, {
method: 'POST',
body: formData,
headers: {
'Accept': 'application/json'
}
})
.then(response => {
if (response.ok) {
showFormMessage('Thank you for your message! I will contact you soon.', 'success');
form.reset();
} else {
throw new Error('Network response was not ok');
}
})
.catch(error => {
console.error('FAILED...', error);
showFormMessage('Sorry, there was an error sending your message. Please try again or contact me directly.', 'error');
})
.finally(() => {
// Reset button state
btnText.style.display = 'block';
btnLoading.style.display = 'none';
submitBtn.disabled = false;
});
});
}
function showFormMessage(message, type) {
// Remove existing messages
const existingMessage = document.querySelector('.form-message');
if (existingMessage) {
existingMessage.remove();
}
// Create new message element
const messageDiv = document.createElement('div');
messageDiv.className = `form-message ${type === 'success' ? 'form-success' : 'form-error'}`;
messageDiv.innerHTML = `
${message}
<button class="close-message" onclick="this.parentElement.remove()">
<i class="fas fa-times"></i>
</button>
`;
// Insert before the form
const form = document.querySelector('.contact-form');
form.parentNode.insertBefore(messageDiv, form);
// Auto remove after 8 seconds
setTimeout(() => {
if (messageDiv.parentElement) {
messageDiv.remove();
}
}, 8000);
}
// Skills animation
function animateSkills() {
const skillBars = document.querySelectorAll('.skill-progress');
skillBars.forEach(bar => {
const level = bar.getAttribute('data-level');
// Delay for sequential animation
const delay = Array.from(skillBars).indexOf(bar) * 200;
setTimeout(() => {
bar.style.width = level + '%';
}, delay);
});
}
// Smooth scrolling
function initSmoothScroll() {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
}
// Mobile menu toggle
function initMobileMenu() {
const toggle = document.querySelector('.nav-toggle');
const navLinks = document.querySelector('.nav-links');
if (toggle && navLinks) {
toggle.addEventListener('click', () => {
const isVisible = navLinks.style.display === 'flex';
navLinks.style.display = isVisible ? 'none' : 'flex';
// Burger menu animation
toggle.classList.toggle('active');
});
}
}
// Header background on scroll
function initHeaderScroll() {
const header = document.querySelector('.header');
window.addEventListener('scroll', () => {
if (window.scrollY > 100) {
header.style.background = 'rgba(14, 18, 28, 0.98)';
header.style.backdropFilter = 'blur(10px)';
} else {
header.style.background = 'rgba(14, 18, 28, 0.95)';
}
});
}
// Initialize when page loads
document.addEventListener('DOMContentLoaded', function() {
initPortfolioFilter();
handleContactForm();
initSmoothScroll();
initMobileMenu();
initHeaderScroll();
// Animate skills when section is in view
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
animateSkills();
}
});
}, { threshold: 0.3 });
const skillsSection = document.querySelector('.skills');
if (skillsSection) {
observer.observe(skillsSection);
}
});
// Page load animation
window.addEventListener('load', function() {
document.body.classList.add('page-loaded');
});