-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
260 lines (220 loc) · 8.39 KB
/
Copy pathscript.js
File metadata and controls
260 lines (220 loc) · 8.39 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
// Mobile Menu Toggle
const menuToggle = document.getElementById('menuToggle');
const navLinks = document.getElementById('navLinks');
if (menuToggle && navLinks) {
menuToggle.addEventListener('click', () => {
navLinks.classList.toggle('active');
menuToggle.innerHTML = navLinks.classList.contains('active') ?
'<i class="fas fa-times"></i>' : '<i class="fas fa-bars"></i>';
});
// Close mobile menu when clicking on a link
document.querySelectorAll('.nav-links a').forEach(link => {
link.addEventListener('click', () => {
navLinks.classList.remove('active');
if (menuToggle) {
menuToggle.innerHTML = '<i class="fas fa-bars"></i>';
}
});
});
}
// Header scroll effect
window.addEventListener('scroll', () => {
const header = document.getElementById('header');
if (header) {
header.classList.toggle('scrolled', window.scrollY > 50);
}
});
// Typing Animation for Hero Subtitle
const text = "Full-Stack Developer";
const typingText = document.querySelector(".typing-text");
let charIndex = 0;
let isDeleting = false;
function type() {
const currentText = text.substring(0, charIndex);
typingText.textContent = currentText;
if (!isDeleting && charIndex < text.length) {
charIndex++;
setTimeout(type, 100);
} else if (isDeleting && charIndex > 0) {
charIndex--;
setTimeout(type, 50);
} else {
isDeleting = !isDeleting;
setTimeout(type, 1000);
}
}
// Scroll reveal animation
function scrollReveal() {
const reveals = document.querySelectorAll('.reveal');
reveals.forEach(reveal => {
const windowHeight = window.innerHeight;
const revealTop = reveal.getBoundingClientRect().top;
const revealPoint = 100;
if (revealTop < windowHeight - revealPoint) {
reveal.classList.add('active');
} else {
reveal.classList.remove('active');
}
});
}
// Animate Progress Bars on Scroll
const skillItems = document.querySelectorAll('.skill-item');
const skillsObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const progressFill = entry.target.querySelector('.progress-fill');
const targetWidth = progressFill.style.width;
progressFill.style.width = '0';
setTimeout(() => {
progressFill.style.width = targetWidth;
}, 100);
}
});
}, { threshold: 0.5 });
skillItems.forEach(item => {
skillsObserver.observe(item);
});
// Fade-in Animation for Timeline Items
const timelineItems = document.querySelectorAll('.timeline-item');
const timelineObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, { threshold: 0.2 });
timelineItems.forEach(item => {
item.style.opacity = '0';
item.style.transform = 'translateY(30px)';
item.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
timelineObserver.observe(item);
});
// Animate cards on scroll
const cards = document.querySelectorAll('.card, .project-card');
const cardObserver = new IntersectionObserver((entries) => {
entries.forEach((entry, index) => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
// Staggered animation
entry.target.style.transition = `opacity 0.6s ease ${index * 0.1}s, transform 0.6s ease ${index * 0.1}s`;
}
});
}, { threshold: 0.1 });
cards.forEach(card => {
card.style.opacity = '0';
card.style.transform = 'translateY(30px)';
cardObserver.observe(card);
});
// Project Filter Functionality
const filterBtns = document.querySelectorAll('.filter-btn');
const projectCards = document.querySelectorAll('.project-card');
filterBtns.forEach(btn => {
btn.addEventListener('click', () => {
// Update active button
filterBtns.forEach(btn => btn.classList.remove('active'));
btn.classList.add('active');
// Filter projects
const filter = btn.dataset.filter;
projectCards.forEach(card => {
if (filter === 'all' || card.dataset.category === filter) {
card.style.display = 'block';
} else {
card.style.display = 'none';
}
});
});
});
// Contact Form Handling with EmailJS
const contactForm = document.getElementById('contact-form');
const formStatus = document.getElementById('form-status');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
// Change button state
const submitBtn = contactForm.querySelector('.submit-btn');
submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Sending...';
submitBtn.disabled = true;
// Send email using EmailJS
emailjs.sendForm('default_service', 'template_w1fz8ll', contactForm)
.then(() => {
formStatus.textContent = 'Message sent successfully!';
formStatus.className = 'form-status success';
contactForm.reset();
}, (error) => {
console.error('FAILED...', error);
formStatus.textContent = 'Oops! Something went wrong. Please try again.';
formStatus.className = 'form-status error';
})
.finally(() => {
submitBtn.innerHTML = '<span class="btn-text">Send Message</span><span class="btn-icon"><i class="fas fa-paper-plane"></i></span>';
submitBtn.disabled = false;
// Hide status message after 5 seconds
setTimeout(() => {
formStatus.textContent = '';
formStatus.className = 'form-status';
}, 5000);
});
});
}
// Input label animation
document.querySelectorAll('.form-group input, .form-group textarea').forEach(input => {
input.addEventListener('focus', () => {
input.previousElementSibling.style.color = 'var(--primary)';
});
input.addEventListener('blur', () => {
if (!input.value) {
input.previousElementSibling.style.color = '#666';
}
});
});
// Initialize all functionality when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
// Start typing animation
setTimeout(type, 1000);
// Initialize scroll reveal
window.addEventListener('scroll', scrollReveal);
window.addEventListener('load', scrollReveal);
// Trigger initial reveal check
scrollReveal();
});
// Dark and Light Mode Toggle
// Theme Toggle Functionality
const themeToggle = document.querySelector('.theme-toggle');
const toggleIcon = themeToggle.querySelector('i');
// Check for saved theme preference or use preferred color scheme
function initializeTheme() {
const savedTheme = localStorage.getItem('theme');
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
if (savedTheme === 'dark' || (!savedTheme && prefersDark)) {
document.documentElement.setAttribute('data-theme', 'dark');
toggleIcon.classList.replace('fa-moon', 'fa-sun');
} else {
document.documentElement.setAttribute('data-theme', 'light');
toggleIcon.classList.replace('fa-sun', 'fa-moon');
}
}
// Toggle theme function
function toggleTheme() {
const currentTheme = document.documentElement.getAttribute('data-theme');
if (currentTheme === 'dark') {
document.documentElement.setAttribute('data-theme', 'light');
localStorage.setItem('theme', 'light');
toggleIcon.classList.replace('fa-sun', 'fa-moon');
} else {
document.documentElement.setAttribute('data-theme', 'dark');
localStorage.setItem('theme', 'dark');
toggleIcon.classList.replace('fa-moon', 'fa-sun');
}
}
// Initialize theme on load
initializeTheme();
// Add event listener to theme toggle
themeToggle.addEventListener('click', toggleTheme);
// Watch for system theme changes
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
if (!localStorage.getItem('theme')) {
initializeTheme();
}
});