-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
60 lines (52 loc) · 1.86 KB
/
script.js
File metadata and controls
60 lines (52 loc) · 1.86 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
(function () {
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
const isMobile = window.matchMedia('(max-width: 760px)').matches;
let progress = document.querySelector('.top-progress');
if (!progress) {
progress = document.createElement('div');
progress.className = 'top-progress';
document.body.appendChild(progress);
}
const updateProgress = () => {
const scrollTop = window.scrollY || document.documentElement.scrollTop;
const docHeight = document.documentElement.scrollHeight - window.innerHeight;
const ratio = docHeight > 0 ? (scrollTop / docHeight) * 100 : 0;
progress.style.width = ratio + '%';
};
updateProgress();
window.addEventListener('scroll', updateProgress, { passive: true });
window.addEventListener('resize', updateProgress);
const revealSelectors = [
'.hero-copy',
'.hero-panel',
'.metric-card',
'.spotlight-card',
'.strength-card',
'.timeline-item',
'.grid-two .card',
'.side-section',
'.identity-card'
];
const items = Array.from(document.querySelectorAll(revealSelectors.join(',')))
.filter((el, idx, arr) => arr.indexOf(el) === idx);
items.forEach((el, index) => {
el.classList.add('reveal');
if (!el.classList.contains('timeline-item')) {
el.classList.add('hover-lift');
}
el.classList.add(`reveal-delay-${index % 3 + 1}`);
});
if (reduceMotion || isMobile || !('IntersectionObserver' in window)) {
items.forEach(el => el.classList.add('is-visible'));
return;
}
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('is-visible');
observer.unobserve(entry.target);
}
});
}, { threshold: 0.03, rootMargin: '0px 0px -6% 0px' });
items.forEach(el => observer.observe(el));
})();