AMBIENT LIGHT
INTERACTION_013CSS + JS
Mouse Glow
Large ambient light that trails the pointer across a section.
Mouse / MediumView
Nearby controls are drawn toward the pointer. At rest in its layout position before the trigger; offsetting the element by 0.3 of the pointer delta and springing back on leave once the pointer entering a 90px radius.
/* Magnetic Elements — Nearby controls are drawn toward the pointer. */
.magnetic-elements {
--dur: 320ms;
--ease: cubic-bezier(0.22, 1, 0.36, 1);
--stagger: 60ms;
will-change: transform, opacity;
}
.magnetic-elements > * {
opacity: 0;
transform: translateY(14px);
animation: magnetic-elements-in var(--dur) var(--ease) forwards;
animation-delay: calc(var(--i, 0) * var(--stagger));
}
/* at rest in its layout position -> offsetting the element by 0.3 of the pointer delta and springing back on leave */
@keyframes magnetic-elements-in {
to {
opacity: 1;
transform: none;
filter: none;
}
}
@media (prefers-reduced-motion: reduce) {
.magnetic-elements > * {
opacity: 1;
transform: none;
animation: none;
}
}import { useEffect, useRef } from "react";
/** Magnetic Elements — trigger: the pointer entering a 90px radius */
export function MagneticElements({ 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-elements" data-state="out">
{children}
</div>
);
}Large ambient light that trails the pointer across a section.
A wide soft light follows the pointer across a dark section.
A short trail of fading dots follows the pointer.
A soft blob lags behind the pointer and deforms with speed.