-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
41 lines (33 loc) · 1.03 KB
/
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
33
34
35
36
37
38
39
40
41
// set current year
const yearEl = document.querySelector(".year");
const currentYear = new Date().getFullYear();
yearEl.textContent = currentYear;
// make mobile nav work
const btnNavEl = document.querySelector(".btn-mobile-nav");
const headerEl = document.querySelector(".header");
btnNavEl.addEventListener('click', function() {
headerEl.classList.toggle('nav-open');
});
// navbar auto close
const navLink = document.querySelector(".main-nav-list");
navLink.addEventListener("click", function () {
headerEl.classList.toggle("nav-open");
});
// sticky navigation
const sectionHeroEl = document.querySelector(".section-hero");
const observer = new IntersectionObserver(function (entries) {
const ent = entries[0];
if(ent.isIntersecting === false) {
document.body.classList.add('sticky')
}
if (ent.isIntersecting) {
document.body.classList.remove("sticky");
}
}, {
// in viewport
root: null,
threshold: 0,
rootMargin: "-80px"
}
);
observer.observe(sectionHeroEl);