Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
173 lines (146 loc) · 6.07 KB
/
Copy pathscript.js
File metadata and controls
173 lines (146 loc) · 6.07 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
document.addEventListener('DOMContentLoaded', () => {
// --- Team member rendering from team.json ---
fetch('team.json')
.then(response => response.json())
.then(data => {
const container = document.getElementById('team-members');
data.forEach(member => {
const card = document.createElement('div');
card.className = 'team-member reveal';
card.innerHTML = `
<h3>${member.name}</h3>
<p><strong>${member.role}</strong></p>
<p>${member.bio}</p>
`;
container.appendChild(card);
});
// Re-observe newly added team cards
card_observer_setup();
});
// --- Navbar scroll behavior ---
const navbar = document.getElementById('navbar');
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
}, { passive: true });
// --- Mobile nav toggle ---
const navToggle = document.getElementById('nav-toggle');
const navLinks = document.querySelector('.nav-links');
navToggle.addEventListener('click', () => {
navToggle.classList.toggle('active');
navLinks.classList.toggle('open');
});
// Close mobile nav on link click
navLinks.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
navToggle.classList.remove('active');
navLinks.classList.remove('open');
});
});
// --- Scroll reveal with Intersection Observer ---
const revealObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
revealObserver.unobserve(entry.target);
}
});
}, {
threshold: 0.15,
rootMargin: '0px 0px -40px 0px'
});
function card_observer_setup() {
document.querySelectorAll('.reveal:not(.visible)').forEach(el => {
revealObserver.observe(el);
});
}
card_observer_setup();
// --- Animated metric counters ---
const metricObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const el = entry.target;
const target = parseInt(el.dataset.target, 10);
animateCounter(el, target);
metricObserver.unobserve(el);
}
});
}, { threshold: 0.5 });
document.querySelectorAll('.metric-number[data-target]').forEach(el => {
metricObserver.observe(el);
});
function animateCounter(el, target) {
const duration = 1200;
const start = performance.now();
function update(now) {
const elapsed = now - start;
const progress = Math.min(elapsed / duration, 1);
// Ease-out cubic
const eased = 1 - Math.pow(1 - progress, 3);
const current = Math.round(eased * target);
el.textContent = current;
if (progress < 1) {
requestAnimationFrame(update);
}
}
requestAnimationFrame(update);
}
// --- Concept image scroll-driven zoom + fade ---
const conceptSection = document.getElementById('concept');
const conceptImg = conceptSection ? conceptSection.querySelector('.concept-img') : null;
const conceptContent = conceptSection ? conceptSection.querySelector('.concept-content') : null;
if (conceptImg) {
const isMobile = window.matchMedia('(max-width: 768px)').matches;
const scaleStart = isMobile ? 0.6 : 0.5;
const scaleEnd = 1;
const radiusStart = 24;
const radiusEnd = 0;
let ticking = false;
function updateConceptScroll() {
const rect = conceptSection.getBoundingClientRect();
const windowH = window.innerHeight;
// Phase 1: Zoom in — as section scrolls into view
// 0 when section top at viewport bottom, 1 when section top at viewport top
const zoomProgress = Math.min(Math.max((windowH - rect.top) / windowH, 0), 1);
const zoomEased = 1 - Math.pow(1 - zoomProgress, 3);
const scale = scaleStart + (scaleEnd - scaleStart) * zoomEased;
const radius = radiusStart + (radiusEnd - radiusStart) * zoomEased;
const zoomOpacity = Math.min(zoomEased * 1.5, 1);
// Phase 2: Fade out — as the content scrolls over the image
let fadeOpacity = 1;
if (conceptContent) {
const contentRect = conceptContent.getBoundingClientRect();
// Fade starts when content top reaches 80% of viewport, ends at 20%
const fadeProgress = Math.min(Math.max((windowH * 0.8 - contentRect.top) / (windowH * 0.6), 0), 1);
fadeOpacity = 1 - fadeProgress;
}
const finalOpacity = zoomOpacity * fadeOpacity;
conceptImg.style.transform = `scale(${scale})`;
conceptImg.style.opacity = finalOpacity;
conceptImg.style.borderRadius = `${radius}px`;
ticking = false;
}
window.addEventListener('scroll', () => {
if (!ticking) {
requestAnimationFrame(updateConceptScroll);
ticking = true;
}
}, { passive: true });
updateConceptScroll();
}
// --- Smooth scroll for nav links (fallback for browsers without CSS smooth scroll) ---
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', (e) => {
const targetId = anchor.getAttribute('href');
if (targetId === '#') return;
const targetEl = document.querySelector(targetId);
if (targetEl) {
e.preventDefault();
targetEl.scrollIntoView({ behavior: 'smooth' });
}
});
});
});