-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
219 lines (190 loc) · 7.58 KB
/
Copy pathscript.js
File metadata and controls
219 lines (190 loc) · 7.58 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
// Function to handle the typing and erasing effect for "about-me" text.
function changeAboutMeText() {
const aboutMeTexts = ["Full Stack Developer", "Software Engineer", "Tech Enthusiast", "Creative Problem Solver"];
const typingSpeed = 100;
const eraseSpeed = 50;
const pauseTime = 1500;
const aboutMeElement = document.querySelector('.about-me');
let textIndex = 0;
let charIndex = 0;
let isDeleting = false;
function type() {
const currentText = aboutMeTexts[textIndex];
// Typing
if (!isDeleting && charIndex < currentText.length) {
aboutMeElement.textContent += currentText[charIndex];
charIndex++;
setTimeout(type, typingSpeed);
}
// Erasing
else if (isDeleting && charIndex > 0) {
aboutMeElement.textContent = currentText.substring(0, charIndex - 1);
charIndex--;
setTimeout(type, eraseSpeed);
}
// Switching mode
else {
isDeleting = !isDeleting;
if (!isDeleting) {
textIndex = (textIndex + 1) % aboutMeTexts.length;
}
setTimeout(type, pauseTime);
}
}
type();
}
// Function to handle the mobile menu toggle
function toggleMenu() {
const navMenu = document.querySelector('.nav-menu');
const menuToggle = document.querySelector('.nav-toggle');
navMenu.classList.toggle('active');
if (navMenu.classList.contains('active')) {
menuToggle.textContent = "✖";
} else {
menuToggle.textContent = "☰";
}
}
// Close mobile menu when a link is clicked
document.querySelectorAll('.nav-menu a').forEach(link => {
link.addEventListener('click', () => {
const navMenu = document.querySelector('.nav-menu');
const menuToggle = document.querySelector('.nav-toggle');
if (navMenu.classList.contains('active')) {
navMenu.classList.remove('active');
menuToggle.textContent = "☰";
}
});
});
// Event listener for Dark Mode toggle, form submission, image modal, and scroll animations
document.addEventListener('DOMContentLoaded', function() {
const darkModeToggle = document.getElementById('dark-mode-toggle');
const body = document.body;
const contactForm = document.querySelector('#contact form');
const formMessage = document.querySelector('.form-message');
// Image Modal elements
const modal = document.getElementById('image-modal');
const modalImg = document.getElementById('full-image');
const modalClose = document.querySelector('.modal-close');
const certCards = document.querySelectorAll('.cert-card');
// Dark Mode Toggle
if (darkModeToggle) {
darkModeToggle.addEventListener('click', () => {
body.classList.toggle('dark-mode');
const isDarkMode = body.classList.contains('dark-mode');
const icon = darkModeToggle.querySelector('i');
if (icon) {
icon.classList.toggle('fa-sun', isDarkMode);
icon.classList.toggle('fa-moon', !isDarkMode);
}
});
}
// Handle form submission (using Formspree)
if (contactForm) {
contactForm.addEventListener('submit', async (e) => {
e.preventDefault();
const form = e.target;
const data = new FormData(form);
const action = form.action;
try {
const response = await fetch(action, {
method: 'POST',
body: data,
headers: {
'Accept': 'application/json'
}
});
if (response.ok) {
formMessage.textContent = "Thank you for your message! It has been sent successfully.";
formMessage.style.display = 'block';
formMessage.style.backgroundColor = '#00ffc8';
formMessage.style.color = '#0d1117';
contactForm.reset();
} else {
formMessage.textContent = "There was an error sending your message. Please try again.";
formMessage.style.backgroundColor = '#f8d7da';
formMessage.style.color = '#721c24';
formMessage.style.display = 'block';
}
} catch (error) {
formMessage.textContent = "Network error. Please check your connection.";
formMessage.style.backgroundColor = '#f8d7da';
formMessage.style.color = '#721c24';
formMessage.style.display = 'block';
}
});
}
// Image modal functionality
if (modal && modalImg && modalClose) {
certCards.forEach(card => {
card.addEventListener('click', () => {
modal.style.display = "block";
modalImg.src = card.dataset.fullImg;
});
});
modalClose.addEventListener('click', () => {
modal.style.display = "none";
});
window.addEventListener('click', (event) => {
if (event.target === modal) {
modal.style.display = "none";
}
});
}
// Toggle active state for experience cards (Glassmorphism & Button)
const experienceCards = document.querySelectorAll('.experience-card');
experienceCards.forEach(card => {
card.addEventListener('click', (e) => {
// Prevent triggering when clicking the link itself if it bubbles up (though link is usually on top)
if (e.target.closest('.project-demo-btn')) return;
// Remove active class from all other cards
experienceCards.forEach(c => {
if (c !== card) {
c.classList.remove('active');
}
});
// Toggle active class on the clicked card
card.classList.toggle('active');
});
});
// Scroll functionality for navigation links
const scrollLinks = document.querySelectorAll('a[href^="#"]');
scrollLinks.forEach(link => {
link.addEventListener('click', (e) => {
const href = link.getAttribute('href');
if (!href || href === '#') return;
e.preventDefault();
const targetId = href.slice(1);
const targetElement = document.getElementById(targetId);
if (targetElement) {
const offset = 100;
const elementPosition = targetElement.getBoundingClientRect().top + window.scrollY;
window.scrollTo({
top: elementPosition - offset,
behavior: 'smooth'
});
}
});
});
// Scroll-reveal animations using IntersectionObserver
const revealItems = document.querySelectorAll(
'.section-container, .education-card, .experience-card, .skill-card, .cert-card, .thumbnail-content'
);
const observerOptions = {
threshold: 0.12
};
const revealObserver = new IntersectionObserver((entries, obs) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('reveal-visible');
entry.target.classList.remove('reveal');
obs.unobserve(entry.target);
}
});
}, observerOptions);
revealItems.forEach(el => {
el.classList.add('reveal');
revealObserver.observe(el);
});
// Start the typing animation on page load
changeAboutMeText();
});