Animations MDB Pro component

Animations - Bootstrap 5 & Material Design 2.0

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.

Note: Read the API tab to find all available options and advanced customization

Move the mouse over the squares below to launch the animation.

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

Basic example

The easiest way to implement the animation is to use data-attributes. In the example below, we use the icon <i class="fas fa-car-side fa-3x"></i> and add the attributes data-toggle="animation" data-animation-reset="true" data-animation="slide-out-right" to give it animation on click.

data-toggle="animation" is an obligatory attribute for each animation.

data-animation-reset="true" lets you decide if the animation can be repeated

data-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.


          <i
            data-toggle="animation"
            data-animation-reset="true"
            data-animation="slide-right"
            class="fas fa-car-side fa-3x"
          ></i>
        

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-dDown
  • 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-attribute.


            <i
              data-toggle="animation"
              data-animation-reset="true"
              data-animation="slide-right"
              class="fas fa-car-side fa-3x"
            ></i>
          

On hover

Use data-animation-start="onHover" to launch the animation on mouse hover.


            <i
              data-toggle="animation"
              data-animation-start="onHover"
              data-animation-reset="true"
              data-animation="slide-right"
              class="fas fa-car-side fa-3x"
            ></i>
          

On scroll

Use data-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.


            <i
              data-toggle="animation"
              data-animation-start="onScroll"
              data-animation="slide-in-left"
              class="fas fa-car-side fa-3x"
            ></i>
          

Repeat animation on scroll

If you want to launch the animation every time it's reached when scrolling use data-animation-on-scroll="repeat".


            <i
              data-toggle="animation"
              data-animation-start="onScroll"
              data-animation-on-scroll="repeat"
              data-animation="slide-in-left"
              class="fas fa-car-side fa-3x"
            ></i>
          

Examples

Examples of practical usage of the animation.

Launching via external element

Click or hover the button to launch the animation.


            <div class="d-flex justify-content-around">
              <div>
                <button
                  class="btn btn-primary mr-5"
                  data-toggle="animation"
                  data-animation-target="#animate-click"
                >
                  Animation on Click
                </button>
                <i
                  id="animate-click"
                  data-animation="slide-out-right"
                  data-animation-start="onClick"
                  data-animation-reset="true"
                  class="fas fa-car-side fa-3x"
                ></i>
              </div>
              <div>
                <button
                  class="btn btn-primary mr-5"
                  data-toggle="animation"
                  data-animation-target="#animate-hover"
                >
                  Animation on Hover
                </button>
                <i
                  id="animate-hover"
                  data-animation="slide-out-right"
                  data-animation-start="onHover"
                  data-animation-reset="true"
                  class="fas fa-car-side fa-3x"
                ></i>
              </div>
            </div>
          

List group

Click "Add" button to add a new item to the list.

  • Cras justo odio
  • Dapibus ac facilisis in
  • Vestibulum at eros

            <div class="d-flex">
              <div class="card" style="width: 18rem;">
                <ul id="example-list" class="list-group list-group-flush">
                  <li class="list-group-item">Cras justo odio</li>
                  <li class="list-group-item">Dapibus ac facilisis in</li>
                  <li class="list-group-item">Vestibulum at eros</li>
                </ul>
              </div>
              <div class="ml-3">
                <button class="btn btn-primary" id="add">
                  add
                </button>
              </div>
            </div>
          

            let elementNumber = 1;
            const bindRemoveClickEvent = (el) => {
              const element = el;
              element.addEventListener('click', () => {
                const prevElement = element.previousElementSibling
                  ? element.previousElementSibling
                  : element;
                const animation = element === prevElement ? 'fade-out' : 'slide-out-up';
                prevElement.style.zIndex = '1';
                element.addEventListener('animationend', () => {
                  element.remove();
                  prevElement.style.zIndex = '0';
                });
                element.classList.add('animation', 'faster', animation);
              });
            };                  
            const addNewOption = () => {
              const element = document.getElementById('example-list');
              const newElement = document.createElement('li');
              const lastElement = element.lastElementChild || element;
              const animation = element === lastElement ? 'fade-in' : 'slide-in-down';
              newElement.innerText = `element ${elementNumber}`;
              lastElement.style.zIndex = '1';
              newElement.classList.add('list-group-item', 'animation', 'faster', animation);
              newElement.addEventListener('animationend', () => {
                lastElement.style.zIndex = '0';
                newElement.classList.remove('animation', 'faster', animation);
              });
              bindRemoveClickEvent(newElement);
              element.appendChild(newElement);
              elementNumber += 1;
            };
            document.querySelectorAll('#example-list li').forEach((el) => {
              bindRemoveClickEvent(el);
            });
            document.getElementById('add').addEventListener('click', () => {
              addNewOption();
            });
          

Accordion

Click the collapsible group of the accordion to see the animation.

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.

            <div class="accordion" id="accordionExample">
              <div class="card">
                <div class="card-header bg-white" id="headingOne">
                  <h2 class="mb-0">
                    <button
                      class="btn btn-link btn-block text-left"
                      type="button"
                      data-toggle="collapse"
                      data-target="#collapseOne"
                      aria-expanded="true"
                      aria-controls="collapseOne"
                    >
                      Collapsible Group Item #1
                    </button>
                  </h2>
                </div>
                <div
                  id="collapseOne"
                  class="collapse show"
                  aria-labelledby="headingOne"
                  data-parent="#accordionExample"
                >
                  <div class="card-body">
                    ...
                  </div>
                </div>
              </div>
              <div class="card">
                <div class="card-header bg-white" id="headingTwo">
                  <h2 class="mb-0">
                    <button
                      class="btn btn-link btn-block text-left collapsed"
                      type="button"
                      data-toggle="collapse"
                      data-target="#collapseTwo"
                      aria-expanded="false"
                      aria-controls="collapseTwo"
                    >
                      Collapsible Group Item #2
                    </button>
                  </h2>
                </div>
                <div
                  id="collapseTwo"
                  class="collapse"
                  aria-labelledby="headingTwo"
                  data-parent="#accordionExample"
                >
                  <div class="card-body">
                    ...
                  </div>
                </div>
              </div>
              <div class="card">
                <div class="card-header bg-white" id="headingThree">
                  <h2 class="mb-0">
                    <button
                      class="btn btn-link btn-block text-left collapsed"
                      type="button"
                      data-toggle="collapse"
                      data-target="#collapseThree"
                      aria-expanded="false"
                      aria-controls="collapseThree"
                    >
                      Collapsible Group Item #3
                    </button>
                  </h2>
                </div>
                <div
                  id="collapseThree"
                  class="collapse"
                  aria-labelledby="headingThree"
                  data-parent="#accordionExample"
                >
                  <div class="card-body">
                    ...
                  </div>
                </div>
              </div>
            </div>
          

            document.querySelectorAll('button[data-toggle="collapse"]').forEach((el) => {
              const animate = new mdb.Animate(el, {
                animation: 'fade-in-up',
                delay: '500',
                duration: '500',
              });
              animate.init();
            });  
          

Animations - API


Usage

Via CSS class


          <i class="fas fa-car-side fa-3x animation slide-out-right"></i>
        

Via data attributes


          <i
            data-toggle="animation"
            data-animation="tada"
            data-animation-start="onLoad"
            class="fas fa-star fa-3x"
          ></i>
        

Via JavaScript


        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-animation String 'fade' Changes animation
animationStart data-animation-start String 'animationOnClick' Set how to run the animation (onClick, onLoad, onScroll, onHover)
animationReset data-animation-reset Boolean false Set to reset the animation after it finishes
animationShowOnLoad data-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-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-animation-offset Number 0 Set offset for animate on scroll
animationDelay data-animation-delay Number 0 Set animation delay
animationDuration data-animation-duration number 500 Set animation duration
animationReverse data-animation-reverse Boolean false Set true to played animation forwards first, then backwards
animationInterval data-animation-interval Number 0 Set the time interval between animations
animationRepeat data-animation-repeat Boolean/Number false Set animation repeat - set true to repeat infinity or enter the number of times the animation should repeat

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.