Skip to content

useScrollToggle

@hua-labs/hua/motion

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

tsx
const toggle = useScrollToggle({
  hideOpacity: 0,
  hideTranslateY: 20,
  scrollThreshold: 0.1,
});

return (
  <div ref={toggle.ref} style={toggle.style}>
    Appears when scrolled into view
  </div>
);

0px

Header

showOpacitynumber1Opacity when element is visible
hideOpacitynumber0Opacity when element is hidden
showScalenumber1Scale when visible
hideScalenumber0.8Scale when hidden
showTranslateYnumber0TranslateY when visible (px)
showRotatenumber0Rotation when visible (degrees)
showTranslateXnumber0TranslateX when visible (px)
hideTranslateYnumber20TranslateY when hidden (px)
hideRotatenumber0Rotation when hidden (degrees)
hideTranslateXnumber0TranslateX when hidden (px)
scrollThresholdnumber0.1Scroll position threshold (0-1, percentage from top)
scrollDirection"up" | "down" | "both""both"Which scroll direction triggers the toggle
durationnumber300Transition duration in milliseconds
easingstring"ease-out"CSS easing function
onComplete() => void-Callback when transition completes
onStart() => void-Callback when transition starts
onStop() => void-Callback when transition is stopped
onReset() => void-Callback when state is reset

refRefObject<T | null>Ref to attach to element
styleCSSPropertiesAnimated style (transform + opacity)
isVisiblebooleanWhether element is in visible state
isAnimatingbooleanWhether transitioning between states
progressnumberTransition progress (0-1)
start() => voidManually trigger show
stop() => voidStop transition
reset() => voidReset to hidden state
pause() => voidPause transition
resume() => voidResume paused transition