Smooth scroll
React Bootstrap 5 Smooth scroll
Bootstrap smooth scroll is an animated movement from a trigger — such as button, link or any other clickable element — to another place of the same page.
Note: Read the API tab to find all available options and advanced customization
Basic example
Click on the links below to see the live example
To achieve a Smooth Scroll effect, use
MDBSmoothScroll
component.
Here it is #section-1
Custom container
By adding containerRef
property you can set container in which you want
smooth scroll.
Here it is #section-2
Custom offset
By adding offset
property you can set custom offset from element.
Here it is #section-3
Custom duration
By adding duration
property you can set custom duration of smooth
scroll.
Here it is #section-4
Custom easing
By adding easing
you can set other scroll's motion option
Here it is #section-5/p>
Container away from viewport
When you put container with overflow: scroll
away from viewport link firstly will
scroll to this container then it will scroll container.
Section to scroll is below:
Here it is #section-6/p>
Smooth scroll - API
Import
Properties
MDBSmoothScroll
Name | Type | Default | Description | Example |
---|---|---|---|---|
containerRef
|
React.RefObject<any> | body |
Reference to container element |
<MDBSmoothScroll
containerRef={exampleRef}>...</MDBSmoothScroll>
|
duration
|
Number | 500 |
Changes duration of smooth scroll. |
<MDBSmoothScroll duration={2000}
>...</MDBSmoothScroll>
|
easing
|
'motionLinear' | 'motionEaseInQuad' | 'motionEaseInCubic' | 'motionEaseInQuart' | 'motionEaseInQuint' | 'motionEaseInOutQuad' | 'motionEaseInOutCubic' | 'motionEaseInOutQuart' | 'motionEaseInOutQuint' | 'motionEaseOutQuad' | 'motionEaseOutCubic' | 'motionEaseOutQuart' | 'motionEaseOutQuint' |
'motionLinear'
|
Changes motion type of smooth scroll. |
<MDBSmoothScroll easing='motionEaseOutCubic' >...</MDBSmoothScroll>
|
offset
|
Number | 0 |
Changes offset from element. |
<MDBSmoothScroll offset={400}
>...</MDBSmoothScroll>
|
tag
|
String | 'div' |
Defines tag of the MDBSmoothScroll wrapper |
<MDBSmoothScroll
tag="span">...</MDBSmoothScroll>
|
targetRef
|
React.RefObject<any> | - |
Reference to target element |
<MDBSmoothScroll
targetRef={exampleRef}>...</MDBSmoothScroll>
|