
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
use-scroll-tracker
Advanced tools
useScrollTracker is a custom React hook that tracks the user's scroll progress on a web page or within a specific container. It returns the current scroll percentage, making it easy to implement features like reading progress bars, infinite scrolling, scr
useScrollTracker
is a custom React hook that tracks the user's scroll progress on a web page or within a specific container. It returns the current scroll percentage, making it easy to implement features like reading progress bars, infinite scrolling, scroll-based animations, and sticky headers. The hook is lightweight, flexible, and suitable for enhancing user experience in React applications. With built-in support for both window and custom container elements, useScrollTracker
helps developers seamlessly integrate scroll-based features into their projects.,
Install the package using npm or yarn:
npm install use-scroll-tracker
The use-scroll-tracker
hook can be useful for a variety of scenarios, including:
The useScrollTracker
hook returns an object with the following properties:
scrollPercentage
: The current scroll percentage of the target element.scrollDirection
: The direction of scrolling. It can be one of the following: up, down, left, right, or null if the direction hasn't changed.The hook accepts an options object with the following properties:
thresholdEvents
: An object where keys are scroll percentages and values are callback functions that trigger when the scroll reaches or exceeds the specified percentage.horizontalScroll
: A boolean to indicate whether the scrolling is horizontal (true) or vertical (false). The default is false (vertical scroll).Here are some improved examples for using the use-scroll-tracker
package with both window objects and HTML elements, along with better CSS styling:
This example demonstrates how to track the scroll progress of the entire window: Live Demo
This example demonstrates how to track the scroll progress of the entire element: Live Demo
If an invalid targetElement
is provided (not an HTMLElement or Window), a warning will be logged to the console:
Invalid targetElement provided. Please provide a valid HTMLElement or use the default window.
Explore more useful packages by visiting my npm profile. Made with ❤️ by Ashish
FAQs
useScrollTracker is a custom React hook that tracks the user's scroll progress on a web page or within a specific container. It returns the current scroll percentage, making it easy to implement features like reading progress bars, infinite scrolling, scr
The npm package use-scroll-tracker receives a total of 10 weekly downloads. As such, use-scroll-tracker popularity was classified as not popular.
We found that use-scroll-tracker demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.