Animations
Bootstrap 5 Animations
Subtle and smooth MDB animations provide the user with a unique experience when interacting with UI. There are several dozen animations at your disposal along with many customization and implementation options.
Bootstrap 5 animations imitate motions for web elements. +70 animations generated by CSS only, work on every browser.
Note: Read the API tab to find all available options and advanced customization
Video tutorial
Move the mouse over the squares below to launch the animation.
Basic example
The easiest way to implement the animation is to use data-mdb-attributes. In the example
below, we use the icon
<i class="fas fa-car-side fa-3x"></i>
and add the attributes
data-mdb-toggle="animation" data-mdb-animation-reset="true"
data-mdb-animation="slide-out-right"
to give it animation on click.
data-mdb-toggle="animation"
is an obligatory attribute for each animation.
data-mdb-animation-reset="true"
lets you decide if the animation can be repeated
data-mdb-animation="slide-right"
lets you specify which animation apply to the
element. In the demo section above you can find available
animations.
Click the car to start the animation.
Animation list
By default, you have access to the basic animations. However, you can also import
_animate-extended.scss
and compile extended animations.
Basic Animations
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
Extended Animations
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
Launch options
There are several options for launching the animation.
On click
Animation on click is a default launching option, so it does not require any data-mdb-attribute.
On hover
Use data-mdb-animation-start="onHover"
to launch the animation on mouse hover.
On Load
Use data-mdb-animation-start="onLoad"
to start the animation after loading the
page. Refresh your browser to see this effect.
Manually
Use data-mdb-animation-start="manually"
to initialize the component without
animating, adding hover, clicking or scrolling events and use the
animationStart
method when you want to start the animation.
On scroll
Use data-mdb-animation-start="onScroll"
to launch the animation when you scroll
the page and reach the element.
Notice that the animation will launch only once - even if you reach it when scrolling multiple times.
Repeat animation on scroll
If you want to launch the animation every time it's reached when scrolling use
data-mdb-animation-on-scroll="repeat"
.
Show on load
If you use animation onScroll
, by default all elements are visible when the
page is loaded. They disappear and begin to animate after the first scroll. You can change
this by setting data-mdb-animation-show-on-load="false"
. However, remember
that this may have a negative impact on SEO.
Examples
Examples of practical usage of the animation.
Launching via external element
Click or hover the button to launch the animation.
Start animation manually
You can use the animationStart
and animationStop
methods to start
or stop the animation at the right moment
Change animation type
You can change the element's animation type at any time using the
changeAnimationType()
method.
Fading gallery
With animation on scroll you can create an impressive gallery that will appear smoothly step by step.
In the example below, we additionally use data-mdb-animation-delay
attribute on
some images to make it appears one by one.
List group
Click "Add" button to add a new item to the list.
- Cras justo odio
- Dapibus ac facilisis in
- Vestibulum at eros
Accordion
Click the collapsible group of the accordion to see the animation.
Animations - API
Usage
Via CSS class
<i class="fas fa-car-side fa-3x animation slide-out-right"></i>
Via data attributes
<i
data-mdb-toggle="animation"
data-mdb-animation="tada"
data-mdb-animation-start="onLoad"
class="fas fa-star fa-3x"
></i>
Via JavaScript
JavaScript with CSS classes:
Note: After JS initializes the animation, the classes responsible for animations will not work.
const element = document.getElementById('example');
const animate = new mdb.Animate(element, { animation: 'tada', });
animate.init();
Via data jQuery
$('#example').animate({ animation: 'tada' });
Options
Name | Data attribute | Type | Default | Description |
---|---|---|---|---|
animation
|
data-mdb-animation
|
String | 'fade' |
Changes animation |
animationStart
|
data-mdb-animation-start
|
String | 'animationOnClick' |
Set how to run the animation (onClick ,
onLoad , onScroll , onHover , manually )
|
animationReset
|
data-mdb-animation-reset
|
Boolean | false |
Set to reset the animation after it finishes |
animationShowOnLoad
|
data-mdb-animation-show-on-load
|
Bollean | true |
Set false to start the scrolling animation immediately after the page
loads. NOTE: this will hide elements that are not currently visible on the screen and
this may have a negative impact on SEO
|
animationOnScroll
|
data-mdb-animation-on-scroll
|
String | once |
Set repeat to start the animation each time the item appears on the screen
|
onStart |
- | Function |
|
Callback function fires after start animation |
onEnd |
- | Function |
|
Callback function fires after end animation |
onHide |
- | Function |
|
Callback function fires after show element |
onShow |
- | Function |
|
Callback function fires after hide element |
animationOffset |
data-mdb-animation-offset
|
Number | 0 |
Set offset for animate on scroll |
animationDelay
|
data-mdb-animation-delay
|
Number | 0 |
Set animation delay |
animationDuration
|
data-mdb-animation-duration
|
number | 500 |
Set animation duration |
animationReverse
|
data-mdb-animation-reverse
|
Boolean | false |
Set true to played animation forwards first, then backwards |
animationInterval
|
data-mdb-animation-interval
|
Number | 0 |
Set the time interval between animations |
animationRepeat
|
data-mdb-animation-repeat
|
Boolean/Number | false |
Set animation repeat - set true to repeat infinity or enter the number of
times the animation should repeat
|
Methods
Name | Description | Example |
---|---|---|
dispose
|
Destroy animations with this method |
animation.dispose()
|
getInstance
|
Static method which allows you to get the animation instance associated to a DOM element. |
Animate.getInstance(animateEl)
|
startAnimation
|
Start animating the element |
animation.startAnimation()
|
stopAnimation
|
Stop animating the element |
animation.stopAnimation()
|
changeAnimationType
|
Change the animation type of an element |
animation.changeAnimationType()
|
const animateEl = document.getElementById('animate');
const animate = new mdb.Animate(manuallyEl, {
animation: 'fade-in',
animationStart: 'manually',
});
animate.startAnimation();
Customize animation via CSS class
Name | Description |
---|---|
infinite
|
Set infinite animation |
delay-1s
|
Set animation delay to delay-1s |
delay-2s
|
Set animation delay to delay-2s |
delay-3s
|
Set animation delay to delay-3s |
delay-4s
|
Set animation delay to delay-4s |
delay-5s
|
Set animation delay to delay-5s |
fast
|
Set animation duration to 800ms |
faster
|
Set animation duration to 500ms |
slow
|
Set animation duration to 2s |
slower
|
Set animation duration to 3s |
Callbacks
Name | Description |
---|---|
onStart
|
This callback fires before the animation starts. |
onEnd
|
This callback starts immediately after the animation has finished. |
onShow
|
If you use animate on scroll this callback will start when the element appears on the screen. |
onHide
|
If you use animate on scroll this callback will start after the element disappears from the screen. |
const animateEl = document.getElementById('animate');
const animate = new mdb.Animate(manuallyEl, {
animation: 'fade-in',
onStart: () => {
// do something.
}
});
animate.init();