Affix
Pin an element to the viewport when scrolling past a threshold.
When to Use
- To keep a toolbar or action bar visible while scrolling
- For sticky navigation that pins to the top or bottom of the viewport
- To ensure important controls remain accessible during scroll
Import
Examples
Offset Top
Pin an element when scrolling past offsetTop pixels from the top.
Offset Bottom
Pin an element relative to the bottom of the viewport.
Note
Affix with offsetBottom is best demonstrated in a full-page context where scrolling activates the pinning behavior.
On Change Callback
Listen for when the affix state changes.
API
AffixProps
offsetTop—number— Pixels from top of viewport to trigger affixoffsetBottom—number— Pixels from bottom of viewport to trigger affixtarget—() => HTMLElement— Custom scroll container (default:window)onChange—(affixed: boolean) => void— Callback when affix state changesclassName—string— Custom CSS classstyle—CSSProperties— Inline styles