VAULT
INTERACTION_050CSS + JS
Scattered Letters Assemble
Characters fly in from random offsets and lock into the word.
Letters / LightView
Characters are pulled toward the cursor then spring back. Letters at rest in their layout positions before the trigger; offsetting each character toward the pointer by 0.25 of the delta, easing back on leave once pointer movement inside the word bounds.
/* Magnetic Characters — Characters are pulled toward the cursor then spring back. */
.magnetic-characters {
--dur: 280ms;
--ease: cubic-bezier(0.22, 1, 0.36, 1);
--stagger: 60ms;
will-change: transform, opacity;
}
.magnetic-characters > * {
opacity: 0;
transform: translateY(14px);
animation: magnetic-characters-in var(--dur) var(--ease) forwards;
animation-delay: calc(var(--i, 0) * var(--stagger));
}
/* letters at rest in their layout positions -> offsetting each character toward the pointer by 0.25 of the delta, easing back on leave */
@keyframes magnetic-characters-in {
to {
opacity: 1;
transform: none;
filter: none;
}
}
@media (prefers-reduced-motion: reduce) {
.magnetic-characters > * {
opacity: 1;
transform: none;
animation: none;
}
}import { useEffect, useRef } from "react";
/** Magnetic Characters — trigger: pointer movement inside the word bounds */
export function MagneticCharacters({ 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="magnetic-characters" data-state="out">
{children}
</div>
);
}Characters fly in from random offsets and lock into the word.
Characters flip on the X axis like a departure board.
Each character rolls up inside its own clipped slot.
Characters lift and brighten as the pointer passes over them.