-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
36 lines (32 loc) · 992 Bytes
/
main.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
33
34
35
36
// ********** set date ************
// select span
const date = (document.getElementById("date").innerHTML =
new Date().getFullYear());
// ********** nav toggle ************
// select button and links
const navBtn = document.getElementById("nav-toggle");
const links = document.getElementById("nav-links");
// add event listener
navBtn.addEventListener("click", () => {
links.classList.toggle("show-links");
});
// ********** smooth scroll ************
// select links
const scrollLinks = document.querySelectorAll(".scroll-link");
scrollLinks.forEach((link) => {
link.addEventListener("click", (e) => {
// prevent default
e.preventDefault();
links.classList.remove("show-links");
const id = e.target.getAttribute("href").slice(1);
const element = document.getElementById(id);
//
let position = element.offsetTop - 62;
window.scrollTo({
left: 0,
// top: element.offsetTop,
top: position,
behavior: "smooth",
});
});
});