-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
21 lines (18 loc) · 802 Bytes
/
Copy pathscript.js
File metadata and controls
21 lines (18 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// JavaScript for smooth scrolling to sections
document.querySelectorAll('.nav-link').forEach(link => {
link.addEventListener('click', (event) => {
event.preventDefault();
// Get the target page from data-page attribute
const targetPage = event.target.getAttribute('data-page');
// Check if the section exists and scroll to it smoothly
const section = document.getElementById(targetPage);
if (section) {
section.scrollIntoView({ behavior: 'smooth' });
// Highlight the current section in the navbar
document.querySelectorAll('.nav-link').forEach(link => {
link.classList.remove('active-link'); // Remove active class from all links
});
event.target.classList.add('active-link'); // Add active class to the clicked link
}
});
});