-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
197 lines (173 loc) · 6.25 KB
/
script.js
File metadata and controls
197 lines (173 loc) · 6.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
// ==========================================
// BADRE ALLOUL PORTFOLIO — INTERACTIVE JS
// ==========================================
document.addEventListener('DOMContentLoaded', () => {
initCursorGlow();
initNavigation();
initScrollAnimations();
initStaggeredAnimations();
});
// ==========================================
// CURSOR GLOW EFFECT
// ==========================================
function initCursorGlow() {
const glow = document.querySelector('.cursor-glow');
if (!glow || window.innerWidth < 768) {
if (glow) glow.style.display = 'none';
return;
}
let mouseX = 0, mouseY = 0;
let glowX = 0, glowY = 0;
document.addEventListener('mousemove', (e) => {
mouseX = e.clientX;
mouseY = e.clientY;
});
function animate() {
glowX += (mouseX - glowX) * 0.06;
glowY += (mouseY - glowY) * 0.06;
glow.style.left = glowX + 'px';
glow.style.top = glowY + 'px';
requestAnimationFrame(animate);
}
animate();
}
// ==========================================
// NAVIGATION
// ==========================================
function initNavigation() {
const toggle = document.querySelector('.nav-toggle');
const menu = document.querySelector('.nav-menu');
const links = document.querySelectorAll('.nav-link');
const navbar = document.querySelector('.navbar');
// Mobile toggle
if (toggle && menu) {
toggle.addEventListener('click', () => {
menu.classList.toggle('active');
toggle.classList.toggle('active');
});
links.forEach(link => {
link.addEventListener('click', () => {
menu.classList.remove('active');
toggle.classList.remove('active');
});
});
}
// Navbar background on scroll
let lastScroll = 0;
window.addEventListener('scroll', () => {
const currentScroll = window.scrollY;
if (currentScroll > 50) {
navbar.style.background = 'rgba(12, 12, 15, 0.95)';
navbar.style.borderColor = 'rgba(42, 42, 50, 0.8)';
} else {
navbar.style.background = 'rgba(12, 12, 15, 0.8)';
navbar.style.borderColor = 'rgba(42, 42, 50, 0.5)';
}
lastScroll = currentScroll;
});
// Active link highlighting
const sections = document.querySelectorAll('section[id]');
window.addEventListener('scroll', () => {
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop - 120;
const sectionHeight = section.offsetHeight;
if (scrollY >= sectionTop && scrollY < sectionTop + sectionHeight) {
current = section.getAttribute('id');
}
});
links.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${current}`) {
link.classList.add('active');
}
});
});
}
// ==========================================
// SCROLL ANIMATIONS
// ==========================================
function initScrollAnimations() {
const animatedElements = document.querySelectorAll(
'.exp-card, .project-card, .stack-category, .article-card, .edu-card, .contact-card'
);
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add('animate-in');
observer.unobserve(entry.target);
}
});
}, {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
});
animatedElements.forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(24px)';
el.style.transition = 'opacity 0.6s cubic-bezier(0.22, 1, 0.36, 1), transform 0.6s cubic-bezier(0.22, 1, 0.36, 1)';
observer.observe(el);
});
// Add CSS class for animation
const style = document.createElement('style');
style.textContent = `
.animate-in {
opacity: 1 !important;
transform: translateY(0) !important;
}
`;
document.head.appendChild(style);
}
// ==========================================
// STAGGERED ANIMATIONS
// ==========================================
function initStaggeredAnimations() {
// Stagger experience cards
const expCards = document.querySelectorAll('.exp-card');
expCards.forEach((card, index) => {
card.style.transitionDelay = `${index * 100}ms`;
});
// Stagger education cards
const eduCards = document.querySelectorAll('.edu-card');
eduCards.forEach((card, index) => {
card.style.transitionDelay = `${index * 100}ms`;
});
// Stagger project cards
const projectCards = document.querySelectorAll('.project-card');
projectCards.forEach((card, index) => {
card.style.transitionDelay = `${index * 80}ms`;
});
// Stagger stack categories
const stackCats = document.querySelectorAll('.stack-category');
stackCats.forEach((cat, index) => {
cat.style.transitionDelay = `${index * 60}ms`;
});
}
// ==========================================
// SMOOTH SCROLL
// ==========================================
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'
});
}
});
});
// ==========================================
// LOGO FALLBACK HANDLING
// ==========================================
document.querySelectorAll('.edu-logo, .company-logo').forEach(img => {
img.addEventListener('error', function() {
// If the image fails to load, show a placeholder icon
this.style.display = 'none';
const wrapper = this.closest('.edu-logo-wrapper, .exp-logo-wrapper');
if (wrapper && !wrapper.querySelector('i')) {
wrapper.innerHTML = '<i class="fas fa-graduation-cap" style="font-size: 2rem; color: var(--accent);"></i>';
}
});
});