Skip to content

useMouse

@hua-labs/hua/motion

bash
npm install @hua-labs/hua
tsx
import { useMouse } from "@hua-labs/hua/framework";

tsx
const { x, y, isOver } = useMouse();

return (
  <div className="relative w-64 h-64 border">
    {isOver && (
      <div
        className="absolute w-4 h-4 bg-primary rounded-full"
        style={{ left: x, top: y, transform: 'translate(-50%, -50%)' }}
      />
    )}
  </div>
);

targetRefRefObject<HTMLElement | null>-Target element ref (defaults to window)
throttlenumber0Throttle interval in milliseconds

xnumberMouse X position (viewport coordinates)
ynumberMouse Y position (viewport coordinates)
elementXnumberRelative X position within target (0-1)
elementYnumberRelative Y position within target (0-1)
isOverbooleanWhether mouse is over the target