forked from apu52/Travel_Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
faq-website.js
85 lines (70 loc) · 2.68 KB
/
faq-website.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
const accordions = document.querySelectorAll(".accordion");
accordions.forEach((accordion, index) => {
const header = accordion.querySelector(".accordion__header");
const content = accordion.querySelector(".accordion__content");
const icon = accordion.querySelector("#accordion-icon");
header.addEventListener("click", () => {
const isOpen = content.style.height === `${content.scrollHeight}px`;
accordions.forEach((a, i) => {
const c = a.querySelector(".accordion__content");
const ic = a.querySelector("#accordion-icon");
c.style.height = i === index && !isOpen ? `${c.scrollHeight}px` : "0px";
ic.classList.toggle("ri-add-line", i !== index || !isOpen);
ic.classList.toggle("ri-subtract-fill", i === index && !isOpen);
});
});
});
document.addEventListener("DOMContentLoaded", function () {
// Highlight active navbar
const navLinks = document.querySelectorAll(".navLinks a");
function highlightNavLink() {
const scrollPosition = window.scrollY;
navLinks.forEach((link) => {
const sectionId = link.getAttribute("href").substring(1);
const section = document.getElementById(sectionId);
// Adjust this value to control when the link should be highlighted
const offsetPercentage = 20;
if (
section.offsetTop - window.innerHeight * (offsetPercentage / 100) <=
scrollPosition &&
section.offsetTop + section.offsetHeight > scrollPosition
) {
link.classList.add("active");
} else {
link.classList.remove("active");
}
});
}
document.addEventListener("scroll", highlightNavLink);
window.addEventListener("resize", highlightNavLink);
// Initialize AOS library
AOS.init();
// Set animation delays for FAQs
const faqs = document.querySelectorAll(".faq");
faqs.forEach((faq, index) => {
faq.style.animationDelay = `${index * 0.2}s`;
});
});
// Logout Button
document.addEventListener("DOMContentLoaded", function () {
var isLoggedIn = localStorage.getItem("isLoggedIn");
var loginButton = document.getElementById("btn-style");
var logoutButton = document.getElementById("logout-btn");
if (isLoggedIn === "true") {
loginButton.style.display = "none";
logoutButton.style.display = "block";
loginButton.disabled = true;
logoutButton.disabled = false;
logoutButton.style.cursor = "pointer";
logoutButton.addEventListener("click", function () {
localStorage.setItem("isLoggedIn", "false");
window.location.href = "./index.html";
});
} else {
loginButton.style.display = "block";
logoutButton.disabled = true;
}
});
function sendEmail() {
window.location.href = "mailto:[email protected]";
}