UNPKG

framer-motion

Version:

An open source and production-ready motion library for React on the web

53 lines (52 loc) • 1.3 kB
import { RefObject } from "react"; import { ScrollMotionValues } from "./utils"; /** * Returns MotionValues that update when the provided element scrolls: * * - `scrollX` — Horizontal scroll distance in pixels. * - `scrollY` — Vertical scroll distance in pixels. * - `scrollXProgress` — Horizontal scroll progress between `0` and `1`. * - `scrollYProgress` — Vertical scroll progress between `0` and `1`. * * This element must be set to `overflow: scroll` on either or both axes to report scroll offset. * * @library * * ```jsx * import * as React from "react" * import { * Frame, * useElementScroll, * useTransform * } from "framer" * * export function MyComponent() { * const ref = React.useRef() * const { scrollYProgress } = useElementScroll(ref) * * return ( * <Frame ref={ref}> * <Frame scaleX={scrollYProgress} /> * </Frame> * ) * } * ``` * * @motion * * ```jsx * export const MyComponent = () => { * const ref = useRef() * const { scrollYProgress } = useElementScroll(ref) * * return ( * <div ref={ref}> * <motion.div style={{ scaleX: scrollYProgress }} /> * </div> * ) * } * ``` * * @public */ export declare function useElementScroll(ref: RefObject<HTMLElement>): ScrollMotionValues;