-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
25 lines (22 loc) · 810 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
// Accurate scroll for nav links
let links = document.querySelectorAll(".link");
let nav = document.querySelector("#nav");
let linksContainer = document.querySelector("#linksContainer");
links.forEach(function(link) {
link.addEventListener("click", function(e) {
e.preventDefault();
const id = e.currentTarget.getAttribute("href").slice(1);
const element = document.getElementById(id);
let navHeight = nav.getBoundingClientRect().height;
const containerHeight = linksContainer.getBoundingClientRect().height;
let position = element.offsetTop - navHeight;
if (id == "home") {
position = 0;
}
window.scrollTo({
left: 0,
top: position,
})
linksContainer.style.height = 0;
})
})