Overview
Thescroll() function creates scroll-linked animations. It can animate elements based on scroll position or link existing animations to scroll progress.
Import
Signature
Parameters
onScroll (required)
A callback function or animation playback controls to link to scroll.container
The scrollable container. Defaults todocument.scrollingElement.
target
The target element to track. When provided, scroll progress is measured relative to this element’s position.axis
The scroll axis to track.offset
Define when the animation starts and ends during scroll.Return Value
Returns a cleanup function to stop tracking scroll.ScrollInfo Interface
Examples
Basic scroll tracking
Animate element on scroll
Track container scroll
Multiple elements animation
Horizontal scroll animation
Parallax effect
Scroll-linked rotation
Notes
- The scroll function automatically handles cleanup when the container is removed from the DOM
- Returns a cleanup function that should be called when you want to stop tracking
- Uses native scroll timeline API when available for better performance
- Falls back to requestAnimationFrame-based implementation when scroll timeline is not supported