-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (49 loc) · 1.67 KB
/
index.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
document.querySelectorAll("nav a").forEach((anchor) => {
anchor.addEventListener("click", function (e) {
e.preventDefault();
document.querySelector(this.getAttribute("href")).scrollIntoView({
behavior: "smooth",
});
});
});
let backToTopBtn = document.createElement("div");
backToTopBtn.innerHTML = '<i class="fas fa-arrow-up"></i>';
backToTopBtn.id = "back-to-top";
document.body.appendChild(backToTopBtn);
window.addEventListener("scroll", () => {
if (window.scrollY > 300) {
backToTopBtn.style.display = "block";
} else {
backToTopBtn.style.display = "none";
}
});
backToTopBtn.addEventListener("click", () => {
window.scrollTo({ top: 0, behavior: "smooth" });
});
const featureItems = document.querySelectorAll(".feature-item");
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("in-view");
}
});
},
{
threshold: 0.1,
}
);
featureItems.forEach((item) => {
observer.observe(item);
});
const faqItems = document.querySelectorAll(".faq-item");
faqItems.forEach((item) => {
const question = item.querySelector(".faq-question");
question.addEventListener("click", () => {
item.classList.toggle("active");
const answer = item.querySelector(".faq-answer");
answer.style.display = answer.style.display === "block" ? "none" : "block";
const chevronIcon = question.querySelector(".fas");
chevronIcon.classList.toggle("rotate");
});
});