Skip to content

Commit f760b1e

Browse files
authored
Create scripts.js
1 parent 87b0860 commit f760b1e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

scripts.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// JavaScript functionality can be added here
2+
3+
// Smooth scrolling for navigation links
4+
document.querySelectorAll('nav a').forEach(anchor => {
5+
anchor.addEventListener('click', function(e) {
6+
e.preventDefault();
7+
document.querySelector(this.getAttribute('href')).scrollIntoView({
8+
behavior: 'smooth'
9+
});
10+
});
11+
});
12+
13+
// Highlight active menu item based on scroll position
14+
const sections = document.querySelectorAll('section');
15+
const navLinks = document.querySelectorAll('nav a');
16+
17+
window.addEventListener('scroll', () => {
18+
let current = '';
19+
sections.forEach(section => {
20+
const sectionTop = section.offsetTop;
21+
if (pageYOffset >= sectionTop - 50) {
22+
current = section.getAttribute('id');
23+
}
24+
});
25+
26+
navLinks.forEach(link => {
27+
link.classList.remove('active');
28+
if (link.getAttribute('href') === `#${current}`) {
29+
link.classList.add('active');
30+
}
31+
});
32+
});

0 commit comments

Comments
 (0)