-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
300 lines (249 loc) · 9.02 KB
/
Copy pathscript.js
File metadata and controls
300 lines (249 loc) · 9.02 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
// ===== Smooth Scrolling =====
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'
});
// Close mobile menu if open
navMenu.classList.remove('active');
hamburger.classList.remove('active');
}
});
});
// ===== Mobile Navigation Toggle =====
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('active');
navMenu.classList.toggle('active');
});
// Close menu when clicking outside
document.addEventListener('click', (e) => {
if (!hamburger.contains(e.target) && !navMenu.contains(e.target)) {
hamburger.classList.remove('active');
navMenu.classList.remove('active');
}
});
// ===== Navbar Background on Scroll =====
const navbar = document.querySelector('.navbar');
let lastScroll = 0;
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
if (currentScroll <= 0) {
navbar.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.3)';
} else {
navbar.style.boxShadow = '0 2px 20px rgba(0, 0, 0, 0.5)';
}
lastScroll = currentScroll;
});
// ===== Active Navigation Link =====
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.nav-link');
function highlightNavigation() {
const scrollY = window.pageYOffset;
sections.forEach(section => {
const sectionHeight = section.offsetHeight;
const sectionTop = section.offsetTop - 100;
const sectionId = section.getAttribute('id');
if (scrollY > sectionTop && scrollY <= sectionTop + sectionHeight) {
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${sectionId}`) {
link.classList.add('active');
}
});
}
});
}
window.addEventListener('scroll', highlightNavigation);
// ===== Intersection Observer for Animations =====
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -100px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('fade-in-up');
observer.unobserve(entry.target);
}
});
}, observerOptions);
// Observe elements for animation
const animateElements = document.querySelectorAll('.project-card, .skill-category, .timeline-item, .about-content');
animateElements.forEach(el => observer.observe(el));
// ===== Typing Effect for Hero Subtitle =====
const heroSubtitle = document.querySelector('.hero-subtitle');
if (heroSubtitle) {
const text = heroSubtitle.textContent;
heroSubtitle.textContent = '';
let i = 0;
function typeWriter() {
if (i < text.length) {
heroSubtitle.textContent += text.charAt(i);
i++;
setTimeout(typeWriter, 100);
}
}
// Start typing effect after a short delay
setTimeout(typeWriter, 500);
}
// ===== Scroll to Top Button =====
const scrollTopBtn = document.createElement('button');
scrollTopBtn.innerHTML = '<i class="fas fa-arrow-up"></i>';
scrollTopBtn.className = 'scroll-top-btn';
scrollTopBtn.style.cssText = `
position: fixed;
bottom: 30px;
right: 30px;
width: 50px;
height: 50px;
background-color: var(--text-highlight);
color: var(--dark-bg);
border: none;
border-radius: 50%;
cursor: pointer;
opacity: 0;
visibility: hidden;
transition: all 0.3s ease;
z-index: 999;
font-size: 20px;
box-shadow: 0 5px 15px rgba(100, 255, 218, 0.3);
`;
document.body.appendChild(scrollTopBtn);
window.addEventListener('scroll', () => {
if (window.pageYOffset > 300) {
scrollTopBtn.style.opacity = '1';
scrollTopBtn.style.visibility = 'visible';
} else {
scrollTopBtn.style.opacity = '0';
scrollTopBtn.style.visibility = 'hidden';
}
});
scrollTopBtn.addEventListener('click', () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
scrollTopBtn.addEventListener('mouseenter', () => {
scrollTopBtn.style.transform = 'scale(1.1)';
});
scrollTopBtn.addEventListener('mouseleave', () => {
scrollTopBtn.style.transform = 'scale(1)';
});
// ===== Project Card Tilt Effect =====
const projectCards = document.querySelectorAll('.project-card');
projectCards.forEach(card => {
card.addEventListener('mousemove', (e) => {
const rect = card.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;
card.style.transform = `perspective(1000px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) translateY(-10px)`;
});
card.addEventListener('mouseleave', () => {
card.style.transform = 'perspective(1000px) rotateX(0) rotateY(0) translateY(0)';
});
});
// ===== Cursor Trail Effect (Optional) =====
const createCursorTrail = () => {
const coords = { x: 0, y: 0 };
const circles = document.querySelectorAll('.cursor-circle');
if (circles.length === 0) {
// Create cursor circles
for (let i = 0; i < 20; i++) {
const circle = document.createElement('div');
circle.className = 'cursor-circle';
circle.style.cssText = `
position: fixed;
width: 10px;
height: 10px;
border-radius: 50%;
background-color: rgba(100, 255, 218, 0.3);
pointer-events: none;
z-index: 9999;
transition: transform 0.1s ease;
`;
document.body.appendChild(circle);
}
}
const circleElements = document.querySelectorAll('.cursor-circle');
circleElements.forEach((circle, index) => {
circle.x = 0;
circle.y = 0;
});
window.addEventListener('mousemove', (e) => {
coords.x = e.clientX;
coords.y = e.clientY;
});
function animateCircles() {
let x = coords.x;
let y = coords.y;
circleElements.forEach((circle, index) => {
circle.style.left = x - 5 + 'px';
circle.style.top = y - 5 + 'px';
circle.style.transform = `scale(${(circleElements.length - index) / circleElements.length})`;
circle.x = x;
circle.y = y;
const nextCircle = circleElements[index + 1] || circleElements[0];
x += (nextCircle.x - x) * 0.3;
y += (nextCircle.y - y) * 0.3;
});
requestAnimationFrame(animateCircles);
}
animateCircles();
};
// Uncomment to enable cursor trail effect
// if (window.innerWidth > 768) {
// createCursorTrail();
// }
// ===== Form Validation (if you add a contact form) =====
const contactForm = document.querySelector('.contact-form');
if (contactForm) {
contactForm.addEventListener('submit', (e) => {
e.preventDefault();
const name = contactForm.querySelector('input[name="name"]').value;
const email = contactForm.querySelector('input[name="email"]').value;
const message = contactForm.querySelector('textarea[name="message"]').value;
if (name && email && message) {
// Here you would typically send the form data to a server
alert('Thank you for your message! I will get back to you soon.');
contactForm.reset();
} else {
alert('Please fill in all fields.');
}
});
}
// ===== Console Message =====
console.log('%c👋 Hello there!', 'color: #64ffda; font-size: 20px; font-weight: bold;');
console.log('%cInterested in the code? Check out the repository!', 'color: #8892b0; font-size: 14px;');
// ===== Performance Optimization =====
// Lazy load images
const images = document.querySelectorAll('img[data-src]');
const imageObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.dataset.src;
img.removeAttribute('data-src');
imageObserver.unobserve(img);
}
});
});
images.forEach(img => imageObserver.observe(img));
// ===== Initialize =====
document.addEventListener('DOMContentLoaded', () => {
// Add loaded class to body for CSS animations
document.body.classList.add('loaded');
// Highlight current navigation on load
highlightNavigation();
});
// Made with Bob