-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
32 lines (26 loc) · 853 Bytes
/
script.js
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
// This function will add a smooth scrolling effect to the navigation links
function smoothScroll() {
// Get all the links on the page
const links = document.querySelectorAll('a');
// Loop through each link
links.forEach(link => {
// Add an event listener to each link
link.addEventListener('click', e => {
// Prevent the default action
e.preventDefault();
// Get the href attribute of the link
const href = link.getAttribute('href');
// Get the element with the corresponding id
const element = document.querySelector(href);
// Calculate the position of the element
const position = element.offsetTop;
// Scroll to the element
window.scrollTo({
top: position,
behavior: 'smooth'
});
});
});
}
// Call the smoothScroll function
smoothScroll();