-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
37 lines (32 loc) · 1.06 KB
/
app.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
37
const openNav = document.querySelector(".hamburger");
const closeNav = document.querySelector(".nav__close");
const nav = document.querySelector(".nav__list");
openNav.addEventListener("click", () => {
const navLeft = nav.getBoundingClientRect().left;
if (navLeft < 0) {
nav.style.left = "0";
document.body.classList.add("active");
}
});
closeNav.addEventListener("click", () => {
const navLeft = nav.getBoundingClientRect().left;
if (navLeft === 0) {
nav.style.left = "-40rem";
document.body.classList.remove("active");
}
});
// Smooth Scroll
const scrollLinks = [...document.querySelectorAll(".scroll-link")];
scrollLinks.forEach(link => {
link.addEventListener("click", e => {
const id = e.target.getAttribute("href").slice(1);
const element = document.getElementById(id);
const position = element.offsetTop;
window.scrollTo({
left: 0,
top: position,
});
nav.style.left = "-40rem";
document.body.classList.remove("active");
});
});