Skip to content
العربية
Motion

usePlayOnce

Plays a picture's CSS animation on view, hover and focus.

import { usePlayOnce } from "@percentsa/motion";

Examples

Plays on view, hover and focus.

Code
export function PlayOnceExample() {
  const t = useT();
  const card = useRef<HTMLDivElement>(null);
  usePlayOnce(card);
  return (
    <div ref={card} tabIndex={0} className="grid w-72 gap-4 rounded-card border border-line bg-surface p-5">
      <div data-picture className="grid h-28 content-end gap-2">
        {[80, 55, 95, 40].map((w) => (
          <span key={w} className="demo-bar block h-3 rounded-pill bg-fg" style={{ width: `${w}%` }} />
        ))}
      </div>
      <Text size="sm" tone="muted">{t("Plays on view, hover and focus.", "يعمل عند الظهور والتمرير والتركيز.")}</Text>
    </div>
  );
}