-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.js
56 lines (50 loc) · 1.63 KB
/
common.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const hamburger = document.querySelector(".hamburger");
const navlinks = document.querySelector(".sm-nav-links");
const navbar = document.querySelector(".nav-bar");
const goUp = document.querySelector(".go-up");
const lazyTargets = document.querySelectorAll(".lazy-load");
// const navShadow = $(".nav-bar .nav-links::after")[0];
// console.log(navShadow);
// toggling the navbar on mobile screens
hamburger.addEventListener("click", () =>{
navlinks.classList.toggle("open");
});
// changing the navbar bg on scroll
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
navbar.style.backgroundColor = "var(--dark-blue)";
navbar.style.boxShadow = "0 0 30px var(--dark-blue)";
} else {
navbar.style.backgroundColor = "transparent";
navbar.style.boxShadow = "none";
}
// toggling the up button
if (goUp) {
if (document.body.scrollTop > 600 || document.documentElement.scrollTop > 600) {
goUp.style.opacity = "1";
goUp.style.pointerEvents = "all";
} else {
goUp.style.opacity = "0";
goUp.style.pointerEvents = "none";
}
}
};
// Lazy load animation
const appearOptions = {
threshold: 0,
rootMargin: "0px 0px -100px 0px"
};
const appearOnScroll = new IntersectionObserver(function (entries, appearOnScroll) {
entries.forEach(entry => {
if (!entry.isIntersecting) {
return;
} else {
entry.target.classList.add("show");
appearOnScroll.unobserve(entry.target);
};
})
}, appearOptions);
lazyTargets.forEach(lazyTarget => {
appearOnScroll.observe(lazyTarget);
});