Skip to content

useMotion

@hua-labs/hua/motion

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

tsx
const motion = useMotion({
  type: 'fadeIn',
  duration: 600,
  autoStart: true,
});

return (
  <div ref={motion.ref} style={motion.style}>
    Fade in on viewport enter
  </div>
);

fadeIn
Fade
slideUp
Slide
scaleIn
Scale
bounceIn
Bounce

typeEntranceType-Motion type: 'fadeIn' | 'slideUp' | 'slideLeft' | 'slideRight' | 'scaleIn' | 'bounceIn'
durationnumber600Animation duration in milliseconds
autoStartbooleantrueAuto start via IntersectionObserver
delaynumber0Delay before animation starts (ms)
easingstring"ease-out"CSS easing function (bounceIn uses cubic-bezier by default)
thresholdnumber0.1Viewport intersection threshold (0-1)
triggerOncebooleantrueOnly trigger animation once
distancenumber50Slide distance in pixels (for slide types)
onComplete() => void-Callback when animation completes
onStart() => void-Callback when animation starts
onStop() => void-Callback when animation is stopped
onReset() => void-Callback when animation is reset

refRefObject<T | null>Ref to attach to animated element
styleCSSPropertiesComputed style with transition properties
isVisiblebooleanWhether element has animated in
isAnimatingbooleanWhether animation is in progress
progressnumberAnimation progress (0-1)
start() => voidStart the animation
stop() => voidStop the animation
reset() => voidReset to initial state

tsx
// Bounce in with custom distance
const motion = useMotion({
  type: 'bounceIn',
  duration: 800,
  distance: 100,
  threshold: 0.2,
  triggerOnce: false,
  onComplete: () => console.log('Animation done!'),
});

return (
  <>
    <button onClick={motion.start}>Replay</button>
    <button onClick={motion.reset}>Reset</button>
    <div ref={motion.ref} style={motion.style}>
      Bounce!
    </div>
  </>
);