-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.min.js
More file actions
35 lines (30 loc) · 1.16 KB
/
jquery.min.js
File metadata and controls
35 lines (30 loc) · 1.16 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
// Toggle Mobile Menu
const menuToggle = document.querySelector('.menu-toggle');
const navbar = document.querySelector('.navbar');
menuToggle.addEventListener('click', () => {
navbar.classList.toggle('active');
});
// Close menu when clicking a link (for mobile)
document.querySelectorAll('.nav-links a').forEach(link => {
link.addEventListener('click', () => {
navbar.classList.remove('active');
});
});
// Highlight active section in navbar
window.addEventListener('scroll', () => {
const sections = document.querySelectorAll('section');
const scrollPosition = window.scrollY + 100;
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.offsetHeight;
const sectionId = section.getAttribute('id');
if (scrollPosition >= sectionTop && scrollPosition < sectionTop + sectionHeight) {
document.querySelectorAll('.nav-links a').forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${sectionId}`) {
link.classList.add('active');
}
});
}
});
});