shadcn-ahooks

useScroll

Get the scroll position of an element.

Overview

Get the scroll position of an element.

Documentation and Examples

Installation

Open in
pnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useScroll.json
npx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useScroll.json
yarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useScroll.json
bun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useScroll.json

Get the scroll position of an element.

Examples

Basic Usage

Detect Whole Page Scroll

Control listen on scroll status

API

const position = useScroll(target, shouldUpdate);

Params

| Property | Description | Type | Default | | | - | ----- | | position | The current scroll position of the element. | { left: number, top: number } \| undefined |

On this page