
Product
Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
@n8tb1t/use-scroll-position
Advanced tools
use-scroll-position
is a lightweight, tree-shakable React hook library for detecting and tracking scroll position — either of the window or a specific element. Designed for performance-sensitive use cases.
⚡️ Version 4.0.0 is a complete rewrite of the library.
For older versions, see the legacy docs.
Track the global window scroll position in just a few lines:
import { useWindowScrollPosition } from '@n8tb1t/use-scroll-position'
useWindowScrollPosition(({ currPos }) => {
console.log('Current scroll position:', currPos.y)
})
Using NPM:
npm install @n8tb1t/use-scroll-position
Using PNPM:
pnpm add @n8tb1t/use-scroll-position
useWindowScrollPosition(({ prevPos, currPos, top, bottom }) => {
console.log(prevPos, currPos, top, bottom)
})
useBodyScrollPosition(({ prevPos, currPos, top, bottom }) => {
console.log(prevPos, currPos, top, bottom)
})
const setElementRef = useWindowScrollPosition(({ prevPos, currPos, top, bottom }) => {
console.log(prevPos, currPos, top, bottom)
})
return <div ref={setElementRef} />
const setElementRef = useBodyScrollPosition(({ prevPos, currPos, top, bottom }) => {
console.log(prevPos, currPos, top, bottom)
})
return <div ref={setElementRef} />
const [setRootRef] = useOverflowScrollPosition(({ prevPos, currPos, top, bottom }) => {
console.log(prevPos, currPos, top, bottom) // root container scroll
})
return (
<div ref={setRootRef} style={{ height: '100px', width: '300px', overflow: 'auto' }} />
)
const [setRootRef, setTargetRef] = useOverflowScrollPosition(({ prevPos, currPos, top, bottom }) => {
console.log(prevPos, currPos, top, bottom) // target element scroll
})
return (
<div ref={setRootRef} style={{ height: '100px', width: '300px', overflow: 'auto' }}>
<div ref={setTargetRef} />
</div>
)
Here are some common ways developers use use-scroll-position
:
See the Contributing Rules.
FAQs
React hook to calculate scroll position
The npm package @n8tb1t/use-scroll-position receives a total of 19,284 weekly downloads. As such, @n8tb1t/use-scroll-position popularity was classified as popular.
We found that @n8tb1t/use-scroll-position demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.