Skip to content

useFadeIn

@hua-labs/hua/motion

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

tsx
const fadeIn = useFadeIn({ duration: 700, delay: 100 });

return (
  <div ref={fadeIn.ref} style={fadeIn.style}>
    This content fades in when scrolled into view
  </div>
);

01
delay: 0ms
02
delay: 200ms
03
delay: 400ms

durationnumber700Animation duration in milliseconds
delaynumber0Delay before animation starts
thresholdnumber0.1Viewport intersection threshold (0-1)
triggerOncebooleantrueOnly trigger animation once
easingstring"ease-out"CSS easing function
autoStartbooleantrueAuto start when element enters viewport
initialOpacitynumber0Initial opacity value
targetOpacitynumber1Target opacity value
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
styleCSSPropertiesAnimated opacity style
isVisiblebooleanWhether element is in viewport
isAnimatingbooleanWhether animation is in progress
progressnumberAnimation progress (0-1)
start() => voidStart animation
stop() => voidStop animation
reset() => voidReset to initial state

tsx
const fadeIn = useFadeIn({
  duration: 700,
  onStart: () => console.log('Animation started'),
  onComplete: () => console.log('Animation complete'),
  onStop: () => console.log('Animation stopped'),
  onReset: () => console.log('Animation reset'),
});