React Bootstrap Sticky Content
React Sticky Content - Bootstrap 4 & Material Design
Note: This documentation is for an older version of Bootstrap (v.4). A
newer version is available for Bootstrap 5. We recommend migrating to the latest version of our product - Material Design for
Bootstrap 5.
Go to docs v.5
Basic example
React Sticky Content - API
In this section you will find advanced information about the Sticky Content component. You will learn which modules are required in this component, what are the possibilities of configuring the component, and what events and methods you can use in working with it.
Import statement
Usage
Step 1: Import and apply the <MDBStickyContent>
component. It will serve as
a wrapper and a
box,
through which we
will be
shaping behaviors of the <MDBSticky>
. Naturally, we can style and populate the <MDBStickyContent>
component
however we see fit.
It
supports all valid <div>
props.
Step 2: Import <MDBSticky>
and place it within
<MDBStickyContent>
. The <MDBSticky>
, again, is a wrapper for content
about to
become sticky, but this time the child elements is getting served in a return statement of a function.
It might be confusing at first, but using such solution allows for more control over the environment where the
stickyness takes place. As you can see below, the function within a <MDBSticky>
may take in
few handy object properties.
API Reference: MDBSticky inner function
The table below shows the configuration options of the function within a <MDBSticky>
component.
Name | Type | Default | Description |
---|---|---|---|
isSticky |
boolean |
|
Determines whether the element is sticky as a result of current event |
wasSticky |
boolean |
|
Is used to determine whether the element was sticky before the event. |
distanceFromTop |
number |
|
Number of pixels from the top of the <Sticky> to the nearest <StickyContainer> 's
top |
distanceFromBottom |
number |
|
Number of pixels from the top of the <Sticky> to the nearest <StickyContainer> 's
bottom |
calculatedHeight |
number |
|
Height of the element returned by this function |
style |
object |
|
Modifiable style attributes to optionally be passed to the element returned by this function |
API Reference: MDBSticky Properties
The table below shows the configuration options of the <MDBSticky>
component.
Name | Type | Default | Description |
---|---|---|---|
relative |
boolean | false |
Set relative to true if the <MDBSticky> element will be rendered within
an
overflowing <MDBStickyContent/>
(e.g. style={{ overflowY: 'auto' }} ) and you want the <MDBSticky>
behavior to react to
events only within that container.
When in relative mode, window events will not trigger sticky
state changes. Only scrolling
within the nearest <MDBStickyContent> can trigger sticky state changes. |
topOffset |
Number | 0 |
Sticky state will be triggered when the top of the element is topOffset pixels from the top
of the closest <MDBStickyContent> .
Positive numbers give the impression of a lazy sticky state, whereas negative numbers are
more eager in their
attachment.topOffset={80} would result in an element that becomes sticky once
its top is greater than or
equal to 80px away from the top of the <MDBStickyContent> .
|
BottomOffset |
number | 0 |
Sticky state will be triggered when the bottom of the element is bottomOffset
pixels from the bottom of
the closest <MDBStickyContent> .
|
disableCompensation |
boolean | false |
Set to true if you do not want your <MDBSticky> to apply
padding to a hidden placeholder
<div> to correct "jumpiness" as attachment changes from position:fixed
and back.
|
disableHardwareAcceleration |
boolean | false |
Height of the element returned by this function |
style |
object |
|
When is set to true , the <MDBSticky> element will not use
hardware acceleration (e.g.
transform: translateZ(0) ). This setting is not recommended as it negatively
impacts the mobile experience,
and can usually be avoided by improving the structure of your DOM.
|