mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-07-30 17:59:13 -04:00
Refine chart animation trigger logic
- Adjusted IntersectionObserver to wait for the entire chart frame to enter the viewport before triggering animation, using `threshold: 1`. - Updated observer options for smoother and more intuitive growth visualization.
This commit is contained in:
@@ -230,15 +230,18 @@ export function MemberGrowth() {
|
||||
setPhase('done')
|
||||
return
|
||||
}
|
||||
// Hold off until the whole figure frame — plot plus its margin — has scrolled into view, not the
|
||||
// instant its top edge appears: the reader is still on the copy above it, and a curve that grows
|
||||
// off-screen isn't watched. threshold: 1 fires only once the entire element is within the viewport.
|
||||
const obs = new IntersectionObserver(
|
||||
(entries) => {
|
||||
if (entries.some((e) => e.isIntersecting)) {
|
||||
if (entries.some((e) => e.intersectionRatio >= 1)) {
|
||||
obs.disconnect()
|
||||
setPhase('drawing')
|
||||
window.setTimeout(() => setPhase('done'), GROWTH_DRAW_MS)
|
||||
}
|
||||
},
|
||||
{rootMargin: '0px 0px -10% 0px'},
|
||||
{threshold: 1},
|
||||
)
|
||||
obs.observe(el)
|
||||
return () => obs.disconnect()
|
||||
|
||||
Reference in New Issue
Block a user