forked from Dearie-de-cybek/GiftCard-landingPage
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
91 lines (72 loc) · 2.08 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
'use strict';
window.CustomSubstackWidget = {
substackUrl: "HoneydropXchange.substack.com",
placeholder: "Enter your email address",
buttonText: "Subscribe",
theme: "custom",
colors: {
primary: "#FFB200",
input: "#FFFFFF",
email: "#A3A2A8",
text: "#FFFFFF",
placeholder: "#A3A2A8"
}
};
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if(entry.isIntersecting){
entry.target.classList.add('show');
} else{
entry.target.classList.remove('show');
}
});
})
const hiddenElements = document.querySelectorAll('.hidden');
hiddenElements.forEach((el) => observer.observe(el));
///////////////////////////////////////////////////////////
// Sticky navigation
const sectionHeroEl = document.querySelector(".section-hero");
const obs = new IntersectionObserver(
function (entries) {
const ent = entries[0];
console.log(ent);
if (ent.isIntersecting === false) {
document.body.classList.add("sticky");
}
if (ent.isIntersecting === true) {
document.body.classList.remove("sticky");
}
},
{
// In the viewport
root: null,
threshold: 0,
rootMargin: "-80px",
}
);
obs.observe(sectionHeroEl);
const btnNavEl = document.querySelector(".btn-mobile-nav");
const headerEl = document.querySelector(".header");
btnNavEl.addEventListener("click", function () {
headerEl.classList.toggle("nav-open");
});
const allLinks = document.querySelectorAll("a:link");
allLinks.forEach(function (link) {
link.addEventListener("click", function (e) {
const href = link.getAttribute("href");
// Scroll back to top
if (href === "#")
window.scrollTo({
top: 0,
behavior: "smooth",
});
// Scroll to other links
if (href !== "#" && href.startsWith("#")) {
const sectionEl = document.querySelector(href);
sectionEl.scrollIntoView({ behavior: "smooth" });
}
// Close mobile naviagtion
if (link.classList.contains("main-nav-link"))
headerEl.classList.toggle("nav-open");
});
});