INTERACTION_015CSS + JS
Scroll Reveal
Content fades and rises as it enters the viewport.
Scroll / LightView
Statistics count up once as they enter view. Showing 0 with fixed tabular width before the trigger; easing the value to its target over the duration with tabular numerals once the stat entering view, once only.
/* Scroll Number Counter — Statistics count up once as they enter view. */
.number-counter {
--dur: 1.4s;
--ease: cubic-bezier(0.22, 1, 0.36, 1);
--stagger: 120ms;
will-change: transform, opacity;
}
.number-counter > * {
opacity: 0;
transform: translateY(14px);
animation: number-counter-in var(--dur) var(--ease) forwards;
animation-delay: calc(var(--i, 0) * var(--stagger));
}
/* showing 0 with fixed tabular width -> easing the value to its target over the duration with tabular numerals */
@keyframes number-counter-in {
to {
opacity: 1;
transform: none;
filter: none;
}
}
@media (prefers-reduced-motion: reduce) {
.number-counter > * {
opacity: 1;
transform: none;
animation: none;
}
}import { useEffect, useRef } from "react";
/** Scroll Number Counter — trigger: the stat entering view, once only */
export function ScrollNumberCounter({ children }: { children: React.ReactNode }) {
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
const el = ref.current;
if (!el) return;
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
el.dataset["state"] = "in";
return;
}
const io = new IntersectionObserver(
([entry]) => {
if (entry?.isIntersecting) {
el.dataset["state"] = "in";
io.unobserve(el);
}
},
{ threshold: 0.2 },
);
io.observe(el);
return () => io.disconnect();
}, []);
return (
<div ref={ref} className="number-counter" data-state="out">
{children}
</div>
);
}Content fades and rises as it enters the viewport.
Children enter in sequence with a fixed delay step.
Three layers move at different speeds to build depth.