forked from sayeeg-11/OpenSource-Compass
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
70 lines (60 loc) · 1.95 KB
/
index.js
File metadata and controls
70 lines (60 loc) · 1.95 KB
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
// Scroll Reveal Animation
const revealElements = document.querySelectorAll('.reveal');
const revealOnScroll = () => {
revealElements.forEach(element => {
const elementTop = element.getBoundingClientRect().top;
const elementVisible = 150;
if (elementTop < window.innerHeight - elementVisible) {
element.classList.add('active');
}
});
};
window.addEventListener('scroll', revealOnScroll);
revealOnScroll(); // Initial check
// Animated Counter
const animateCounter = (element) => {
const target = parseInt(element.getAttribute('data-target'));
const duration = 2000;
const increment = target / (duration / 16);
let current = 0;
const updateCounter = () => {
current += increment;
if (current < target) {
element.textContent = Math.floor(current).toLocaleString();
requestAnimationFrame(updateCounter);
} else {
if (target >= 1000) {
element.textContent = (target / 1000) + 'K+';
} else if (target >= 5) {
element.textContent = target + 'Y+';
} else {
element.textContent = target + '+';
}
}
};
updateCounter();
};
// Trigger counters when stats section is visible
const statsSection = document.querySelector('.stats-section');
let counterTriggered = false;
const checkStatsVisible = () => {
if (!counterTriggered) {
const sectionTop = statsSection.getBoundingClientRect().top;
if (sectionTop < window.innerHeight - 200) {
counterTriggered = true;
document.querySelectorAll('.counter').forEach(counter => {
animateCounter(counter);
});
}
}
};
window.addEventListener('scroll', checkStatsVisible);
checkStatsVisible();
// Newsletter form
const newsletterForm = document.querySelector('.newsletter-form');
newsletterForm.addEventListener('submit', (e) => {
e.preventDefault();
const email = e.target.querySelector('input').value;
alert(`Thank you for subscribing! We'll send updates to ${email}`);
e.target.reset();
});