
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
advanced-scroll-hook
Advanced tools
A powerful React hook for advanced scroll tracking, control, and animations. Perfect for creating scroll-based interactions, progress indicators, parallax effects, and intelligent scroll snapping.
npm install advanced-scroll-hook
import { useScroll } from 'advanced-scroll-hook'
function MyComponent() {
const { scrollData, setScroll } = useScroll()
return (
<div>
<div>Scroll: {scrollData.percent * 100}%</div>
<button onClick={() => setScroll(0, true)}>
Go to Top
</button>
</div>
)
}
Returns an object with scroll data and control functions.
interface UseScrollOptions {
container?: HTMLElement | null // Custom scroll container (default: window)
startHeight?: number // Start position in pixels (default: 0)
endHeight?: number // End position in pixels (default: document height)
}
interface UseScrollReturn {
scrollData: {
scrollY: number // Current scroll position in pixels
percent: number // Scroll percentage (0-1, can exceed bounds)
direction: 'up' | 'down' | 'none' // Scroll direction
isScrolling: boolean // Whether currently scrolling
}
percentToScrollHeight: (percent: number) => number // Convert percent to pixels
setScroll: (position: number, smooth?: boolean) => void // Scroll to position
}
import { useScroll } from 'advanced-scroll-hook'
function ScrollProgress() {
const { scrollData } = useScroll()
return (
<div className="progress-bar">
<div
className="progress-fill"
style={{ width: `${scrollData.percent * 100}%` }}
/>
</div>
)
}
Track scroll progress for a specific element within the viewport:
// Calculate scroll range for the target element
const calculateScrollRange = useCallback(() => {
const rect = keyDivRef.current.getBoundingClientRect()
const keyDivTop = rect.top + window.scrollY
return {
startHeight: keyDivTop, // When div top hits screen top
endHeight: keyDivTop + rect.height - window.innerHeight
}
}, [])
const { scrollData } = useScroll({
startHeight: scrollRange.startHeight,
endHeight: scrollRange.endHeight,
})
// Animate based on scroll progress
<div style={{
transform: `scale(${0.8 + scrollData.percent * 0.4})`,
opacity: scrollData.percent < 0 || scrollData.percent > 1 ? 0.3 : 1
}}>
Content scales as you scroll!
</div>
Create a three-page experience with scroll-based navigation:
// Calculate current page based on scroll percentage
const getCurrentPage = (percent: number) => {
if (percent < 0.3333) return 1
if (percent < 0.6666) return 2
return 3
}
// Jump to specific page
const goToPage = (page: number) => {
const targetPercent = page === 1 ? 0 : page === 2 ? 0.5 : 1
const targetHeight = percentToScrollHeight(targetPercent)
setScroll(targetHeight, true)
}
// Navigation buttons
{[1, 2, 3].map((page) => (
<button onClick={() => goToPage(page)}>
{page}
</button>
))}
Create intelligent directional scroll snapping with threshold-based page navigation:
// Smart snapping logic with 15% threshold
const handleSmartSnap = useCallback(() => {
const snapPoints = [0, 0.5, 1]
const distanceFromLast = Math.abs(scrollData.percent - lastSnapPositionRef.current)
const threshold = 0.15
if (distanceFromLast < threshold) return
let targetSnap = null
if (scrollData.direction === 'down') {
targetSnap = snapPoints.find(point => point > lastSnapPositionRef.current)
} else if (scrollData.direction === 'up') {
targetSnap = snapPoints.reverse().find(point => point < lastSnapPositionRef.current)
}
if (targetSnap !== null) {
setScroll(percentToScrollHeight(targetSnap), true)
lastSnapPositionRef.current = targetSnap
}
}, [scrollData.percent, scrollData.direction])
// Trigger snapping when scroll stops
useEffect(() => {
if (!scrollData.isScrolling) {
setTimeout(handleSmartSnap, 50)
}
}, [scrollData.isScrolling, handleSmartSnap])
# Install dependencies
npm install
# Start demo development server
npm run dev
# Build library
npm run build:lib
# Build demo
npm run build:demo
# Build both
npm run build
src/
├── lib/ # Library source
│ ├── index.ts # Main export
│ └── useScroll.ts # Hook implementation
└── demo/ # Demo application
├── App.tsx # Demo app with examples
├── main.tsx
└── index.html
MIT © gaomeng1900
FAQs
A lightweight React hook for scroll tracking and snapping.
The npm package advanced-scroll-hook receives a total of 4 weekly downloads. As such, advanced-scroll-hook popularity was classified as not popular.
We found that advanced-scroll-hook 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.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.