-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
53 lines (48 loc) · 1.69 KB
/
Copy pathscript.js
File metadata and controls
53 lines (48 loc) · 1.69 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
// Navbar scroll effect
const navbar = document.getElementById('navbar');
window.addEventListener('scroll', () => {
navbar.classList.toggle('scrolled', window.scrollY > 20);
});
// Mobile nav toggle
const navToggle = document.getElementById('navToggle');
const navLinks = document.getElementById('navLinks');
navToggle.addEventListener('click', () => {
navLinks.classList.toggle('open');
navToggle.classList.toggle('active');
});
// Close mobile nav on link click
navLinks.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
navLinks.classList.remove('open');
navToggle.classList.remove('active');
});
});
// Active nav link on scroll
const sections = document.querySelectorAll('section[id]');
function updateActiveLink() {
const scrollY = window.scrollY + 100;
sections.forEach(section => {
const top = section.offsetTop;
const height = section.offsetHeight;
const id = section.getAttribute('id');
const link = document.querySelector(`.nav-links a[href="#${id}"]`);
if (link) {
link.classList.toggle('active', scrollY >= top && scrollY < top + height);
}
});
}
window.addEventListener('scroll', updateActiveLink);
// Fade-in on scroll (Intersection Observer)
const fadeEls = document.querySelectorAll('.section-title, .card, .pub-item, .skill-category, .timeline-item, .highlight-card, .contact-item, .about-text');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
}, { threshold: 0.15 });
fadeEls.forEach(el => {
el.classList.add('fade-in');
observer.observe(el);
});