-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
375 lines (322 loc) · 11 KB
/
script.js
File metadata and controls
375 lines (322 loc) · 11 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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
document.addEventListener('DOMContentLoaded', function () {
console.log('Alasrambus site loaded');
// ===== Theme Toggle =====
const themeToggle = document.getElementById('themeToggle');
const themeIcon = document.getElementById('themeIcon');
const html = document.documentElement;
// Check for saved theme preference or default to light mode
const currentTheme = localStorage.getItem('theme') || 'dark';
html.setAttribute('data-theme', currentTheme);
updateThemeIcon(currentTheme);
// Enable smooth transition on theme change
function enableThemeTransition() {
html.style.transition = 'background-color 0.4s ease, color 0.4s ease';
document.body.style.transition = 'background-color 0.4s ease, color 0.4s ease';
setTimeout(() => {
html.style.transition = '';
document.body.style.transition = '';
}, 600);
}
themeToggle.addEventListener('click', () => {
const currentTheme = html.getAttribute('data-theme');
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
enableThemeTransition();
html.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
updateThemeIcon(newTheme);
});
function updateThemeIcon(theme) {
if (theme === 'dark') {
themeIcon.className = 'fas fa-sun';
} else {
themeIcon.className = 'fas fa-moon';
}
}
// ===== Floating Navigation =====
const nav = document.getElementById('navFloating');
let lastScroll = 0;
let ticking = false;
window.addEventListener('scroll', () => {
if (!ticking) {
window.requestAnimationFrame(() => {
const currentScroll = window.pageYOffset;
if (currentScroll > 100) {
if (currentScroll > lastScroll) {
// Scrolling down
nav.classList.remove('visible');
} else {
// Scrolling up
nav.classList.add('visible');
}
} else {
nav.classList.remove('visible');
}
lastScroll = currentScroll;
ticking = false;
});
ticking = true;
}
});
// ===== Smooth Scroll for Navigation Links =====
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const offset = 80; // Account for fixed nav
const targetPosition = target.getBoundingClientRect().top + window.pageYOffset - offset;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
// Mark hero parts visible on load to trigger CSS keyframes
document.querySelectorAll('.hero-left, .hero-right').forEach(el => {
requestAnimationFrame(() => el.classList.add('visible'));
});
// ===== Intersection Observer for Fade-in Animations =====
const observerOptions = {
threshold: 0.15,
rootMargin: '0px 0px -80px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry, index) => {
if (entry.isIntersecting) {
// Add staggered delay for multiple elements
setTimeout(() => {
entry.target.classList.add('visible');
}, index * 100);
}
});
}, observerOptions);
// Observe all elements with fade-in-scroll class and stat items
document.querySelectorAll('.fade-in-scroll, .stat-item').forEach(el => {
observer.observe(el);
});
// ===== Email Subscription Form =====
const subscribeForm = document.getElementById('subscribeForm');
const emailInput = document.getElementById('emailInput');
if (subscribeForm) {
subscribeForm.addEventListener('submit', function (e) {
e.preventDefault();
const email = emailInput.value.trim();
if (email && validateEmail(email)) {
// Show success message
showNotification('Thank you for subscribing! You\'ll hear from me soon.', 'success');
emailInput.value = '';
} else {
showNotification('Please enter a valid email address.', 'error');
}
});
}
// ===== Email Validation =====
function validateEmail(email) {
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return re.test(email);
}
// ===== Notification System =====
function showNotification(message, type) {
// Create notification element
const notification = document.createElement('div');
notification.className = `notification notification-${type}`;
notification.textContent = message;
// Use CSS variables for colors
const styles = getComputedStyle(document.documentElement);
const primary = styles.getPropertyValue('--primary') || '#00B3FF';
const danger = '#e74c3c';
// Add styles
notification.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
padding: 1rem 1.5rem;
background: ${type === 'success' ? primary : danger};
color: white;
border-radius: 8px;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
z-index: 10000;
animation: slideIn 0.3s ease-out;
font-family: 'Inter', sans-serif;
font-weight: 500;
`;
// Add animation
const style = document.createElement('style');
style.textContent = `
@keyframes slideIn {
from {
transform: translateX(400px);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
@keyframes slideOut {
from {
transform: translateX(0);
opacity: 1;
}
to {
transform: translateX(400px);
opacity: 0;
}
}
`;
document.head.appendChild(style);
// Append to body
document.body.appendChild(notification);
// Remove after 4 seconds
setTimeout(() => {
notification.style.animation = 'slideOut 0.3s ease-out';
setTimeout(() => {
notification.remove();
}, 300);
}, 4000);
}
// ===== Parallax Effect for Hero Section =====
const hero = document.querySelector('.hero');
let parallaxTicking = false;
if (hero) {
window.addEventListener('scroll', () => {
if (!parallaxTicking) {
window.requestAnimationFrame(() => {
const scrolled = window.pageYOffset;
const parallax = scrolled * 0.3;
hero.style.transform = `translateY(${parallax}px)`;
parallaxTicking = false;
});
parallaxTicking = true;
}
});
}
// ===== Enhanced Project Card Interactions =====
const projectCards = document.querySelectorAll('.project-card');
projectCards.forEach((card, index) => {
// Staggered entrance animation
card.style.opacity = '0';
card.style.transform = 'translateY(30px)';
setTimeout(() => {
card.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
card.style.opacity = '1';
card.style.transform = 'translateY(0)';
}, 100 * index);
// Add ripple effect on click
card.addEventListener('click', function(e) {
const ripple = document.createElement('span');
ripple.classList.add('ripple');
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';
const styles = getComputedStyle(document.documentElement);
const primary = styles.getPropertyValue('--primary').trim() || '#00B3FF';
ripple.style.cssText += `
position: absolute;
border-radius: 50%;
background: ${primary}30;
transform: scale(0);
animation: ripple 0.6s ease-out;
pointer-events: none;
z-index: 10;
`;
this.appendChild(ripple);
setTimeout(() => ripple.remove(), 600);
});
// Add 3D tilt effect on mouse move
card.addEventListener('mousemove', function(e) {
const rect = this.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const centerX = rect.width / 2;
const centerY = rect.height / 2;
const rotateX = (y - centerY) / 20;
const rotateY = (centerX - x) / 20;
this.style.transform = `perspective(1000px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) translateY(-12px) scale(1.03)`;
});
card.addEventListener('mouseleave', function() {
this.style.transform = '';
});
});
// Add ripple animation and shimmer effect
const style = document.createElement('style');
style.textContent = `
@keyframes ripple {
to {
transform: scale(4);
opacity: 0;
}
}
@keyframes shimmer {
0% {
background-position: -1000px 0;
}
100% {
background-position: 1000px 0;
}
}
.project-card::after {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(
90deg,
transparent,
rgba(255, 255, 255, 0.2),
transparent
);
transition: left 0.5s ease;
}
.project-card:hover::after {
left: 100%;
}
`;
document.head.appendChild(style);
// ===== Smooth Gradient Blobs Animation =====
const blobs = document.querySelectorAll('.gradient-blob');
blobs.forEach((blob, index) => {
let x = 0, y = 0;
const speed = 0.5 + index * 0.2;
function animateBlob() {
x += Math.sin(Date.now() * 0.001 * speed) * 0.5;
y += Math.cos(Date.now() * 0.001 * speed) * 0.5;
blob.style.transform = `translate(${x}px, ${y}px)`;
requestAnimationFrame(animateBlob);
}
animateBlob();
});
// ===== Enhanced CTA Button Interactions =====
const ctaButtons = document.querySelectorAll('.cta-button');
ctaButtons.forEach(button => {
button.addEventListener('mouseenter', function() {
this.style.transition = 'all 0.3s cubic-bezier(0.4, 0, 0.2, 1)';
});
});
// ===== Smooth Page Load Animation =====
window.addEventListener('load', () => {
document.body.style.opacity = '0';
setTimeout(() => {
document.body.style.transition = 'opacity 0.5s ease-in';
document.body.style.opacity = '1';
}, 100);
});
// ===== Add Hover Sound Effect (Optional) =====
const interactiveElements = document.querySelectorAll('.cta-button, .project-card, .social-link');
interactiveElements.forEach(element => {
element.addEventListener('mouseenter', () => {
element.style.transition = 'all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1)';
});
});
// ===== Console Easter Egg =====
console.log('%c👋 Hey there!', 'font-size: 24px; font-weight: bold; color: #00B3FF;');
console.log('%cLooking at the code? I like your style!', 'font-size: 14px; color: #666666;');
console.log('%cFeel free to reach out if you want to collaborate: hello@alasrambus.com', 'font-size: 12px; color: #8B5CF6;');
});