-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavaScript.js
More file actions
24 lines (19 loc) · 746 Bytes
/
Copy pathjavaScript.js
File metadata and controls
24 lines (19 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
document.addEventListener("DOMContentLoaded", function() {
const links = document.querySelectorAll('.nav-items a[href^="#"]');
links.forEach(link => {
link.addEventListener("click", function(e) {
e.preventDefault();
const targetId = this.getAttribute("href");
const targetElement = document.querySelector(targetId);
if (targetElement) {
// Calculate distance from the top of the page to the target element
const offsetTop = targetElement.offsetTop;
// Smooth scroll animation
window.scrollTo({
top: offsetTop,
behavior: "smooth"
});
}
});
});
});