-
Notifications
You must be signed in to change notification settings - Fork 260
/
Copy pathcustom.js
76 lines (63 loc) · 2.23 KB
/
custom.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
//show answer and change indicator for /FAQ page
function toggleAnswer(answerId, element) {
const answer = document.getElementById(answerId);
const indicator = element.querySelector('.indicator');
if (answer) {
answer.classList.toggle('d-none');
if (answer.classList.contains('d-none')) {
indicator.innerHTML = '+';
} else {
indicator.innerHTML = '-';
}
}
}
// Counter Animation of the home page
document.addEventListener('DOMContentLoaded', () => {
const counters = document.querySelectorAll('.count');
// Function to animate the counter
function animateCounter(counter) {
const target = +counter.getAttribute('data-target');
const speed = 200;
const updateCount = () => {
const current = +counter.innerText.replace(/,/g, '');
const increment = Math.ceil(target / speed);
if (current < target) {
counter.innerText = Math.min(current + increment, target).toLocaleString();
setTimeout(updateCount, 10);
} else if (target === 170) {
counter.innerText = target.toLocaleString();
} else {
counter.innerText = target.toLocaleString() + '+';
}
};
updateCount();
}
const observerOptions = {
root: null,
threshold: 0.3
};
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
animateCounter(entry.target);
observer.unobserve(entry.target);
}
});
}, observerOptions);
counters.forEach(counter => {
observer.observe(counter);
});
});
//Donation Banner
// Ensures that the buttons have loaded correctly before executing code
document.addEventListener('DOMContentLoaded', () => {
const donateBanner = document.getElementById("donation-banner");
const closeBtn = document.getElementById("close-icon");
if (closeBtn) {
closeBtn.addEventListener("click", () => {
if (donateBanner) {
donateBanner.style.display = "none"; // Hide the banner on click
}
});
}
});