-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
64 lines (55 loc) · 2.1 KB
/
Copy pathscript.js
File metadata and controls
64 lines (55 loc) · 2.1 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
document.addEventListener('DOMContentLoaded', () => {
// Mobile Navigation Toggle
const mobileBtn = document.querySelector('.mobile-menu-btn');
const navLinks = document.querySelector('.nav-links');
if(mobileBtn) {
mobileBtn.addEventListener('click', () => {
navLinks.classList.toggle('active');
});
}
// Close mobile nav when clicking a link
const links = document.querySelectorAll('.nav-links a');
links.forEach(link => {
link.addEventListener('click', () => {
navLinks.classList.remove('active');
});
});
// Scroll reveal animation using Intersection Observer
const sections = document.querySelectorAll('.section-reveal');
const observerOptions = {
root: null,
rootMargin: '0px',
threshold: 0.15
};
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
// Uncomment the line below to only animate once
// observer.unobserve(entry.target);
}
});
}, observerOptions);
sections.forEach(section => {
observer.observe(section);
});
// Active state for navigation based on scroll position
const allSections = document.querySelectorAll('section, footer');
const navItems = document.querySelectorAll('.nav-links a');
window.addEventListener('scroll', () => {
let current = '';
allSections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (pageYOffset >= (sectionTop - sectionHeight / 3)) {
current = section.getAttribute('id');
}
});
navItems.forEach(item => {
item.classList.remove('active');
if (item.getAttribute('href').slice(1) === current) {
item.classList.add('active');
}
});
});
});