-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
122 lines (104 loc) · 3.52 KB
/
Copy pathscript.js
File metadata and controls
122 lines (104 loc) · 3.52 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* ============================================================
THE ELEPHANT — script.js
============================================================ */
/* ── 1. Scroll Reveal ─────────────────────────────────────── */
(function () {
const revealEls = document.querySelectorAll('.reveal');
const revealObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
revealObserver.unobserve(entry.target);
}
});
},
{ threshold: 0.12 }
);
revealEls.forEach((el) => revealObserver.observe(el));
})();
/* ── 2. Number Counter Animation ─────────────────────────── */
(function () {
const counters = document.querySelectorAll('[data-target]');
const fired = new Set();
function easeOut(t) {
return 1 - Math.pow(1 - t, 3);
}
function animateCounter(el) {
const target = parseFloat(el.dataset.target);
const isBill = el.classList.contains('bill-num');
const duration = 1200;
const start = performance.now();
function tick(now) {
const elapsed = now - start;
const progress = Math.min(elapsed / duration, 1);
const value = Math.round(easeOut(progress) * target);
el.textContent = isBill
? value.toLocaleString('en-US')
: value;
if (progress < 1) requestAnimationFrame(tick);
else el.textContent = isBill
? target.toLocaleString('en-US')
: target;
}
requestAnimationFrame(tick);
}
const counterObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting && !fired.has(entry.target)) {
fired.add(entry.target);
animateCounter(entry.target);
}
});
},
{ threshold: 0.3 }
);
counters.forEach((el) => counterObserver.observe(el));
})();
/* ── 3. Terminal Typewriter ───────────────────────────────── */
(function () {
const INTERVAL = 120; // ms per line
function initTerminal(terminalEl) {
const lines = terminalEl.querySelectorAll('.terminal-line');
let played = false;
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting && !played) {
played = true;
observer.disconnect();
playTerminal(lines);
}
});
},
{ threshold: 0.3 }
);
observer.observe(terminalEl);
}
function playTerminal(lines) {
lines.forEach((line, i) => {
setTimeout(() => {
line.classList.add('show');
}, i * INTERVAL);
});
}
document.querySelectorAll('.terminal-body').forEach(initTerminal);
})();
/* ── 4. Flip Cards ────────────────────────────────────────── */
(function () {
document.querySelectorAll('.guardrail-card').forEach((card) => {
card.addEventListener('click', () => {
card.classList.toggle('flipped');
});
// Keyboard accessibility
card.setAttribute('tabindex', '0');
card.setAttribute('role', 'button');
card.addEventListener('keydown', (e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
card.classList.toggle('flipped');
}
});
});
})();