-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
41 lines (34 loc) · 1.41 KB
/
script.js
File metadata and controls
41 lines (34 loc) · 1.41 KB
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
// Selecting some elements so that we can manipulate the accordion when the user clicks on it.
const itemElement = document.querySelector(".item");
const parentElement = document.querySelector(".accordion");
// When one of the accordion elements is clicked, we first find it using the closest method and then toggle the open class on it.
parentElement.addEventListener("click", function (e) {
e.preventDefault();
const clicked = e.target.closest(".item");
clicked.classList.toggle("open");
});
// Selecting the hero section so that we when the user leave it, we make the navigation sticky.
const hero = document.querySelector(".section-hero");
// Creating our Intersection observer.
const obs = new IntersectionObserver(
function (entries) {
// Getting our entrie
const ent = entries[0];
// When the user stops intersection with the hero page(main page) and leave it, we add our sticky navigation.
if (ent.isIntersecting === false) {
document.body.classList.add("sticky");
}
// When the user is back to the main page, start intersection we then remove the sticky navigation and put it back to normal.
if (ent.isIntersecting === true) {
document.body.classList.remove("sticky");
}
},
// some options we pass to our intersection observer.
{
root: null,
threshold: 0,
rootMargin: "-80px",
}
);
// Setting the goal of the observer on our main hero page.
obs.observe(hero);