Sticky
React Bootstrap 5 Sticky
Sticky element can be locked in a particular area of the page. It is often used in navigation menus.
Note: Read the API tab to find all available options and advanced customization
Basic example
To start use sticky just create MDBSticky
component or useStickyRef
hook
Sticky bottom
You can pin the element to the bottom by passing
position="bottom"
as a prop
Boundary
Set boundary
so that sticky only works inside the parent
element. Remember to set the correct parent height.
Outer element as a boundary
You can specify an element reference to be the sticky boundary by passing
boundary={elementReference}

Direction
Default scrolling direction is down
. You can change it by setting
direction="top"
or
direction="both"
Animation
You can add an animation that will run when the sticky starts and when the sticky element is
hidden. Just specify the CSS class of the animation using the
animationSticky
and
animationUnsticky
properties.
Remember that not every animation will be appropriate. We suggest using the animations used in the example below.
Sticky - API
Import
Properties
MDBSticky
Name | Type | Default | Description | Example |
---|---|---|---|---|
animationSticky
|
'fade-in' | 'fade-in-down' | 'fade-in-left' | 'fade-in-right' | 'fade-in-up' | 'fade-out' | 'fade-out-down' | 'fade-out-left' | 'fade-out-right' | 'fade-out-up' | 'slide-in-down' | 'slide-in-left' | 'slide-in-right' | 'slide-in-up' | 'slide-out-down' | 'slide-out-left' | 'slide-out-right' | 'slide-out-up' | 'slide-down' | 'slide-left' | 'slide-right' | 'slide-up' | 'zoom-in' | 'zoom-out' | 'tada' | 'pulse' | 'drop-in' | 'drop-out' | 'fly-in' | 'fly-in-up' | 'fly-in-down' | 'fly-in-left' | 'fly-in-right' | 'fly-out' | 'fly-out-up' | 'fly-out-down' | 'fly-out-left' | 'fly-out-right' | 'browse-in' | 'browse-out' | 'browse-out-left' | 'browse-out-right' | 'jiggle' | 'flash' | 'shake' | 'glow' | '' |
Set sticky animation |
<MDBSticky animationSticky="fade-in" />
|
animationUnsticky
|
'fade-in' | 'fade-in-down' | 'fade-in-left' | 'fade-in-right' | 'fade-in-up' | 'fade-out' | 'fade-out-down' | 'fade-out-left' | 'fade-out-right' | 'fade-out-up' | 'slide-in-down' | 'slide-in-left' | 'slide-in-right' | 'slide-in-up' | 'slide-out-down' | 'slide-out-left' | 'slide-out-right' | 'slide-out-up' | 'slide-down' | 'slide-left' | 'slide-right' | 'slide-up' | 'zoom-in' | 'zoom-out' | 'tada' | 'pulse' | 'drop-in' | 'drop-out' | 'fly-in' | 'fly-in-up' | 'fly-in-down' | 'fly-in-left' | 'fly-in-right' | 'fly-out' | 'fly-out-up' | 'fly-out-down' | 'fly-out-left' | 'fly-out-right' | 'browse-in' | 'browse-out' | 'browse-out-left' | 'browse-out-right' | 'jiggle' | 'flash' | 'shake' | 'glow' | '' |
Set unsticky animation |
<MDBSticky animationUnsticky="fade-out" />
|
boundary
|
boolean | false |
Set to true to stop sticky on the end of the parent |
<MDBSticky boundary />
|
delay
|
number | 0 |
Set the number of pixels beyond which the item will be pinned |
<MDBSticky delay={100} />
|
direction
|
'up' | 'down' | 'both' | 'down' |
Set the scrolling direction for which the element is to be stikcky |
<MDBSticky direction='up' />
|
offset
|
Number | 0 |
Set the distance from the top edge of the element for which the element is sticky |
<MDBSticky offset={100} />
|
position
|
'top' | 'bottom' | 'top' |
Set the edge of the screen the item should stick to |
<MDBSticky position="down" />
|
stickyRef
|
React.RefObject | '' |
Sets a reference for the MDBSticky element. |
<MDBSticky stickyRef={exampleRef} />
|
useStickyRef
Name | Type | Default | Description | Example |
---|---|---|---|---|
animationSticky
|
'fade-in' | 'fade-in-down' | 'fade-in-left' | 'fade-in-right' | 'fade-in-up' | 'fade-out' | 'fade-out-down' | 'fade-out-left' | 'fade-out-right' | 'fade-out-up' | 'slide-in-down' | 'slide-in-left' | 'slide-in-right' | 'slide-in-up' | 'slide-out-down' | 'slide-out-left' | 'slide-out-right' | 'slide-out-up' | 'slide-down' | 'slide-left' | 'slide-right' | 'slide-up' | 'zoom-in' | 'zoom-out' | 'tada' | 'pulse' | 'drop-in' | 'drop-out' | 'fly-in' | 'fly-in-up' | 'fly-in-down' | 'fly-in-left' | 'fly-in-right' | 'fly-out' | 'fly-out-up' | 'fly-out-down' | 'fly-out-left' | 'fly-out-right' | 'browse-in' | 'browse-out' | 'browse-out-left' | 'browse-out-right' | 'jiggle' | 'flash' | 'shake' | 'glow' | '' |
Set sticky animation |
useStickyRef({ animationSticky: 'fade-in' })
|
animationUnsticky
|
'fade-in' | 'fade-in-down' | 'fade-in-left' | 'fade-in-right' | 'fade-in-up' | 'fade-out' | 'fade-out-down' | 'fade-out-left' | 'fade-out-right' | 'fade-out-up' | 'slide-in-down' | 'slide-in-left' | 'slide-in-right' | 'slide-in-up' | 'slide-out-down' | 'slide-out-left' | 'slide-out-right' | 'slide-out-up' | 'slide-down' | 'slide-left' | 'slide-right' | 'slide-up' | 'zoom-in' | 'zoom-out' | 'tada' | 'pulse' | 'drop-in' | 'drop-out' | 'fly-in' | 'fly-in-up' | 'fly-in-down' | 'fly-in-left' | 'fly-in-right' | 'fly-out' | 'fly-out-up' | 'fly-out-down' | 'fly-out-left' | 'fly-out-right' | 'browse-in' | 'browse-out' | 'browse-out-left' | 'browse-out-right' | 'jiggle' | 'flash' | 'shake' | 'glow' | '' |
Set unsticky animation |
useStickyRef({ animationUnsticky: 'fade-out' })
|
boundary
|
boolean | false |
Set to true to stop sticky on the end of the parent |
useStickyRef({ boundary: true })
|
delay
|
number | 0 |
Set the number of pixels beyond which the item will be pinned |
useStickyRef({ delay: 100 })
|
direction
|
'up' | 'down' | 'both' | 'down' |
Set the scrolling direction for which the element is to be stikcky |
useStickyRef({ direction: 'up' })
|
offset
|
Number | 0 |
Set the distance from the top edge of the element for which the element is sticky |
useStickyRef({ offset: 100 })
|
position
|
'top' | 'bottom' | 'top' |
Set the edge of the screen the item should stick to |
useStickyRef({ position: 'down' })
|
Events
MDBSticky
Name | Type | Description |
---|---|---|
onActive
|
() => any | This event fires immediately when the element is active |
onInactive
|
() => any | This event fires immediately when the element is inactive |