-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
293 lines (246 loc) · 9.25 KB
/
script.js
File metadata and controls
293 lines (246 loc) · 9.25 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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
// ===== DOM ELEMENTS =====
const navbar = document.getElementById('navbar');
const navToggle = document.getElementById('navToggle');
const navLinks = document.getElementById('navLinks');
const navLinkItems = document.querySelectorAll('.nav-link');
// ===== NAVBAR SCROLL EFFECT =====
let lastScroll = 0;
window.addEventListener('scroll', () => {
const currentScroll = window.scrollY;
if (currentScroll > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
lastScroll = currentScroll;
});
// ===== MOBILE MENU TOGGLE =====
navToggle.addEventListener('click', () => {
navToggle.classList.toggle('open');
navLinks.classList.toggle('open');
document.body.style.overflow = navLinks.classList.contains('open') ? 'hidden' : '';
});
navLinkItems.forEach(link => {
link.addEventListener('click', () => {
navToggle.classList.remove('open');
navLinks.classList.remove('open');
document.body.style.overflow = '';
});
});
// ===== ACTIVE NAV LINK ON SCROLL =====
const sections = document.querySelectorAll('section[id]');
function updateActiveNav() {
const scrollY = window.scrollY + 100;
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.offsetHeight;
const sectionId = section.getAttribute('id');
if (scrollY >= sectionTop && scrollY < sectionTop + sectionHeight) {
navLinkItems.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${sectionId}`) {
link.classList.add('active');
}
});
}
});
}
window.addEventListener('scroll', updateActiveNav);
// ===== TYPEWRITER EFFECT =====
const typewriterEl = document.getElementById('typewriter');
const roles = [
'Flutter Developer',
'Mobile App Developer',
'UI/UX Enthusiast',
'Problem Solver',
'Freelancer'
];
let roleIndex = 0;
let charIndex = 0;
let isDeleting = false;
let typeSpeed = 100;
function typeWriter() {
const currentRole = roles[roleIndex];
if (isDeleting) {
typewriterEl.textContent = currentRole.substring(0, charIndex - 1);
charIndex--;
typeSpeed = 50;
} else {
typewriterEl.textContent = currentRole.substring(0, charIndex + 1);
charIndex++;
typeSpeed = 100;
}
if (!isDeleting && charIndex === currentRole.length) {
typeSpeed = 2000;
isDeleting = true;
} else if (isDeleting && charIndex === 0) {
isDeleting = false;
roleIndex = (roleIndex + 1) % roles.length;
typeSpeed = 500;
}
setTimeout(typeWriter, typeSpeed);
}
typeWriter();
// ===== COUNTER ANIMATION =====
function animateCounters() {
const counters = document.querySelectorAll('.stat-number');
counters.forEach(counter => {
const target = parseInt(counter.getAttribute('data-target'));
const duration = 2000;
const step = target / (duration / 16);
let current = 0;
const updateCounter = () => {
current += step;
if (current < target) {
counter.textContent = Math.ceil(current);
requestAnimationFrame(updateCounter);
} else {
counter.textContent = target;
}
};
updateCounter();
});
}
// ===== PARTICLE SYSTEM =====
function createParticles() {
const container = document.getElementById('particles');
if (!container) return;
const particleCount = 30;
for (let i = 0; i < particleCount; i++) {
const particle = document.createElement('div');
particle.classList.add('particle');
const size = Math.random() * 3 + 1;
particle.style.width = `${size}px`;
particle.style.height = `${size}px`;
particle.style.left = `${Math.random() * 100}%`;
particle.style.animationDuration = `${Math.random() * 15 + 10}s`;
particle.style.animationDelay = `${Math.random() * 10}s`;
const colors = ['#6c5ce7', '#a29bfe', '#00cec9'];
particle.style.background = colors[Math.floor(Math.random() * colors.length)];
container.appendChild(particle);
}
}
createParticles();
// ===== SCROLL REVEAL ANIMATION =====
function setupScrollReveal() {
const revealTargets = document.querySelectorAll(
'.about-grid, .about-image-card, .about-content-col, ' +
'.timeline-item, .usp-card, .exp-card, .achievement-card, ' +
'.project-card, .service-card, .testimonial-card, ' +
'.contact-info, .contact-form-wrapper, .section-header'
);
revealTargets.forEach(el => el.classList.add('reveal'));
const revealObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('revealed');
revealObserver.unobserve(entry.target);
}
});
}, {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
});
revealTargets.forEach(el => revealObserver.observe(el));
}
// Run when DOM is ready
document.addEventListener('DOMContentLoaded', () => {
setupScrollReveal();
});
// ===== COUNTER TRIGGER ON SCROLL =====
let counterTriggered = false;
const heroSection = document.getElementById('home');
const counterObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting && !counterTriggered) {
counterTriggered = true;
animateCounters();
}
});
}, { threshold: 0.3 });
if (heroSection) counterObserver.observe(heroSection);
// ===== TESTIMONIALS SLIDER =====
const testimonialCards = document.querySelectorAll('.testimonial-card');
const dots = document.querySelectorAll('.testimonial-dots .dot');
const prevBtn = document.getElementById('prevTestimonial');
const nextBtn = document.getElementById('nextTestimonial');
let currentTestimonial = 0;
function showTestimonial(index) {
testimonialCards.forEach(card => card.classList.remove('active'));
dots.forEach(dot => dot.classList.remove('active'));
currentTestimonial = (index + testimonialCards.length) % testimonialCards.length;
testimonialCards[currentTestimonial].classList.add('active');
dots[currentTestimonial].classList.add('active');
}
if (prevBtn && nextBtn) {
prevBtn.addEventListener('click', () => showTestimonial(currentTestimonial - 1));
nextBtn.addEventListener('click', () => showTestimonial(currentTestimonial + 1));
}
dots.forEach((dot, index) => {
dot.addEventListener('click', () => showTestimonial(index));
});
// Auto-slide testimonials
setInterval(() => {
showTestimonial(currentTestimonial + 1);
}, 5000);
// ===== CONTACT FORM WITH EMAILJS =====
const contactForm = document.getElementById('contactForm');
if (contactForm) {
// Initialize EmailJS with Public Key
// IMPORTANT: Replace 'YOUR_PUBLIC_KEY' with your actual EmailJS Public Key
(function() {
emailjs.init({
publicKey: "YOUR_PUBLIC_KEY",
});
})();
contactForm.addEventListener('submit', (e) => {
e.preventDefault();
const btn = contactForm.querySelector('.btn');
const btnText = btn.querySelector('span');
const btnIcon = btn.querySelector('i');
const originalText = btnText.textContent;
const originalIconClass = btnIcon.className;
// Loading state
btn.disabled = true;
btnText.textContent = 'Sending...';
btnIcon.className = 'bx bx-loader-alt bx-spin';
// Send email using EmailJS
// Replace 'YOUR_SERVICE_ID' and 'YOUR_TEMPLATE_ID' with yours
emailjs.sendForm('YOUR_SERVICE_ID', 'YOUR_TEMPLATE_ID', contactForm)
.then(() => {
// Success state
btn.style.background = 'linear-gradient(135deg, #00cec9, #55efc4)';
btnText.textContent = 'Message Sent!';
btnIcon.className = 'bx bx-check';
contactForm.reset();
setTimeout(() => {
btn.disabled = false;
btn.style.background = '';
btnText.textContent = originalText;
btnIcon.className = originalIconClass;
}, 3000);
}, (error) => {
// Error state
console.error('FAILED...', error);
btn.style.background = 'linear-gradient(135deg, #ff7675, #d63031)';
btnText.textContent = 'Error sending!';
btnIcon.className = 'bx bx-error-circle';
setTimeout(() => {
btn.disabled = false;
btn.style.background = '';
btnText.textContent = originalText;
btnIcon.className = originalIconClass;
}, 3000);
});
});
}
// ===== SMOOTH SCROLL FOR ALL ANCHOR LINKS =====
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' });
}
});
});