INTERACTION_015CSS + JS
Scroll Reveal
Content fades and rises as it enters the viewport.
Scroll / LightView
Page surfaces shift tone as each section takes over. The first section's tone before the trigger; interpolating the background color to the incoming section's tone once each section crossing the viewport midpoint.
/* Background Color Transition — Page surfaces shift tone as each section takes over. */
.background-color-transition {
--dur: 700ms;
--ease: cubic-bezier(0.22, 1, 0.36, 1);
--stagger: 60ms;
will-change: transform, opacity;
}
.background-color-transition > * {
opacity: 0;
transform: translateY(14px);
animation: background-color-transition-in var(--dur) var(--ease) forwards;
animation-delay: calc(var(--i, 0) * var(--stagger));
}
/* the first section's tone -> interpolating the background color to the incoming section's tone */
@keyframes background-color-transition-in {
to {
opacity: 1;
transform: none;
filter: none;
}
}
@media (prefers-reduced-motion: reduce) {
.background-color-transition > * {
opacity: 1;
transform: none;
animation: none;
}
}import { useEffect, useRef } from "react";
/** Background Color Transition — trigger: each section crossing the viewport midpoint */
export function BackgroundColorTransition({ 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="background-color-transition" 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.