-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
281 lines (242 loc) · 9.45 KB
/
script.js
File metadata and controls
281 lines (242 loc) · 9.45 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
// Mobile menu toggle
document.addEventListener('DOMContentLoaded', function() {
const mobileMenuButton = document.getElementById('mobile-menu-button');
const mobileMenu = document.getElementById('mobile-menu');
if (mobileMenuButton) {
mobileMenuButton.addEventListener('click', function() {
mobileMenu.classList.toggle('open');
});
}
// Close mobile menu when clicking on a link
const mobileLinks = document.querySelectorAll('#mobile-menu a');
mobileLinks.forEach(link => {
link.addEventListener('click', function() {
mobileMenu.classList.remove('open');
});
});
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const navHeight = document.querySelector('nav').offsetHeight;
const targetPosition = target.getBoundingClientRect().top + window.pageYOffset - navHeight;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
// Intersection Observer for reveal animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver(function(entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('active');
}
});
}, observerOptions);
// Observe all reveal elements
document.querySelectorAll('.reveal').forEach(el => {
observer.observe(el);
});
// Add scroll event for navbar shadow
let lastScroll = 0;
const nav = document.querySelector('nav');
window.addEventListener('scroll', function() {
const currentScroll = window.pageYOffset;
if (currentScroll > 10) {
nav.classList.add('nav-shadow');
} else {
nav.classList.remove('nav-shadow');
}
lastScroll = currentScroll;
});
// Counter animation
function animateCounter(element, target, duration = 2000) {
let current = 0;
const increment = target / (duration / 16);
const timer = setInterval(() => {
current += increment;
if (current >= target) {
element.textContent = target;
clearInterval(timer);
} else {
element.textContent = Math.floor(current);
}
}, 16);
}
// Animate counters when they come into view
const counterObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting && !entry.target.classList.contains('counted')) {
const target = parseInt(entry.target.getAttribute('data-target'));
animateCounter(entry.target, target);
entry.target.classList.add('counted');
}
});
}, { threshold: 0.5 });
document.querySelectorAll('.counter').forEach(counter => {
counterObserver.observe(counter);
});
// Parallax effect for hero section (subtle, no overlapping)
const heroSection = document.querySelector('.hero-parallax');
if (heroSection) {
window.addEventListener('scroll', function() {
const scrolled = window.pageYOffset;
const heroContent = heroSection.querySelector('.hero-content');
if (heroContent && scrolled < window.innerHeight) {
heroContent.style.transform = `translateY(${scrolled * 0.3}px)`;
heroContent.style.opacity = 1 - (scrolled / window.innerHeight);
}
});
}
// Add ripple effect to buttons
document.querySelectorAll('.ripple').forEach(button => {
button.addEventListener('click', function(e) {
const ripple = document.createElement('span');
const rect = this.getBoundingClientRect();
const size = Math.max(rect.width, rect.height);
const x = e.clientX - rect.left - size / 2;
const y = e.clientY - rect.top - size / 2;
ripple.style.width = ripple.style.height = size + 'px';
ripple.style.left = x + 'px';
ripple.style.top = y + 'px';
ripple.classList.add('ripple-effect');
this.appendChild(ripple);
setTimeout(() => ripple.remove(), 600);
});
});
// Progress bar animation
const skillBars = document.querySelectorAll('.skill-bar-fill');
const skillObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const width = entry.target.getAttribute('data-width');
entry.target.style.width = width;
}
});
}, { threshold: 0.5 });
skillBars.forEach(bar => {
skillObserver.observe(bar);
});
// Typing effect for hero subtitle
const typingElement = document.querySelector('.typing-text');
if (typingElement) {
const text = typingElement.textContent;
typingElement.textContent = '';
let i = 0;
function typeWriter() {
if (i < text.length) {
typingElement.textContent += text.charAt(i);
i++;
setTimeout(typeWriter, 100);
}
}
setTimeout(typeWriter, 500);
}
// Stagger animation for feature cards
const featureCards = document.querySelectorAll('.feature-card');
const cardObserver = new IntersectionObserver((entries) => {
entries.forEach((entry, index) => {
if (entry.isIntersecting) {
setTimeout(() => {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}, index * 100);
}
});
}, { threshold: 0.1 });
featureCards.forEach(card => {
card.style.opacity = '0';
card.style.transform = 'translateY(30px)';
card.style.transition = 'all 0.5s ease';
cardObserver.observe(card);
});
// Particle effect in hero section (simple version)
function createParticles() {
const particleContainer = document.getElementById('particles');
if (!particleContainer) return;
for (let i = 0; i < 50; i++) {
const particle = document.createElement('div');
particle.className = 'particle';
particle.style.cssText = `
position: absolute;
width: ${Math.random() * 5 + 2}px;
height: ${Math.random() * 5 + 2}px;
background: rgba(255, 255, 255, ${Math.random() * 0.5 + 0.2});
border-radius: 50%;
left: ${Math.random() * 100}%;
top: ${Math.random() * 100}%;
animation: float ${Math.random() * 10 + 5}s infinite ease-in-out;
animation-delay: ${Math.random() * 5}s;
`;
particleContainer.appendChild(particle);
}
}
createParticles();
// Add active class to current section in navigation
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('nav a[href^="#"]');
window.addEventListener('scroll', () => {
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (pageYOffset >= sectionTop - 200) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('text-indigo-600', 'font-bold');
if (link.getAttribute('href') === `#${current}`) {
link.classList.add('text-indigo-600', 'font-bold');
}
});
});
// Add loading animation
window.addEventListener('load', function() {
document.body.classList.add('loaded');
});
// Easter egg: Konami code
let konamiCode = [];
const konamiPattern = ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'b', 'a'];
document.addEventListener('keydown', (e) => {
konamiCode.push(e.key);
konamiCode = konamiCode.slice(-10);
if (konamiCode.join('') === konamiPattern.join('')) {
document.body.style.animation = 'rainbow 2s linear infinite';
}
});
});
// Add rainbow animation for easter egg
const style = document.createElement('style');
style.textContent = `
@keyframes rainbow {
0% { filter: hue-rotate(0deg); }
100% { filter: hue-rotate(360deg); }
}
.ripple-effect {
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, 0.6);
transform: scale(0);
animation: ripple-animation 0.6s ease-out;
pointer-events: none;
}
@keyframes ripple-animation {
to {
transform: scale(4);
opacity: 0;
}
}
.particle {
pointer-events: none;
}
`;
document.head.appendChild(style);