UNPKG

framer-motion

Version:

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

41 lines (40 loc) • 1.14 kB
import { ScrollMotionValues } from "./utils"; /** * Returns MotionValues that update when the viewport 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`. * * **Warning:** Setting `body` or `html` to `height: 100%` or similar will break the `Progress` * values as this breaks the browser's capability to accurately measure the page length. * * @library * * ```jsx * import * as React from "react" * import { * Frame, * useViewportScroll, * useTransform * } from "framer" * * export function MyComponent() { * const { scrollYProgress } = useViewportScroll() * return <Frame scaleX={scrollYProgress} /> * } * ``` * * @motion * * ```jsx * export const MyComponent = () => { * const { scrollYProgress } = useViewportScroll() * return <motion.div style={{ scaleX: scrollYProgress }} /> * } * ``` * * @public */ export declare function useViewportScroll(): ScrollMotionValues;