Quick Tip: Scroll Animations With fullPage.js and Animate.css
In a previous tutorial, I introduced you to fullPage.js, a popular jQuery plugin for building full-screen pages. In this quick tip, I’ll show you how to create scroll-based animations with fullPage.js and animate.css.
Required Libraries
For the purposes of this example, I set up a demo page. If you look under the Settings tab, you’ll see I included the following libraries to the pen:
- fullPage.js
- animate.css
- jQuery
- Bootstrap


The Bootstrap framework isn’t vital; I added it only because I wanted to take advantage of its styles.
The Process
Our page comprises four sections; each one filling the page (thanks to fullPage). Users will jump to the next section by scrolling, or navigating via the pagination links on the right. Each time that happens we’ll trigger some animations, like bringing the images into position, for example.


Before showing the code that fires the animations, let’s first cover the required steps:
- We need to take advantage of the “callback” functions that fullPage provides. More specifically, in our case, we want to animate the second, third, and fourth sections, so we’ll use the
onLeavecallback. If we wanted to animate the first section, we could have used theafterLoadcallback. In the same way, for animating the slides we should use theafterSlideLoadandonSlideLeavefunctions. - We’ll dynamically add CSS animations provided by the
animate.csslibrary using jQuery. - We’ll also animate elements sequentially using the
animate-delayCSS property.
Now, let’s dive into the animations!
Animation #1
The second section of the page includes three images and one button. Here’s its structure:
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
A Simple Button |
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
Notice that we’ve added the is-animated and is-animated__single classes to the elements that we want to animate. Additionally, keep in mind that the elements with the is-animated class will share the same animation effect (e.g. fadeInUpBig).
The jQuery code that triggers the animations for this section looks like this:
1 |
|
2 |
var $isAnimatedSecond = $('.second .is-animated'), |
3 |
$isAnimatedSecondSingle = $('.second .is-animated__single'); |
4 |
|
5 |
/* this code is part of the onLeave callback */
|
6 |
if( index == 1 && nextIndex == 2 ) { |
7 |
$isAnimatedSecond.addClass('animated fadeInUpBig'); |
8 |
$isAnimatedSecond.eq(0).css('animation-delay', '.3s'); |
9 |
$isAnimatedSecond.eq(1).css('animation-delay', '.6s'); |
10 |
$isAnimatedSecond.eq(2).css('animation-delay', '.9s'); |
11 |
$isAnimatedSecondSingle.addClass('animated rollIn').css('animation-delay', '1.7s'); |
12 |
}
|
13 |
In this example, when we leave the first section and move to the second one, we apply two different animations (i.e. fadeInUpBig and rollIn) to the target elements. In addition, we use the animation-delay CSS property to specify when those animations should start.
Animation #2
The third section contains two images and one button. Below you can see the corresponding HTML code:
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
A Simple Button |
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
As with the previous example, we’ve added the is-animated and is-animated__single classes to the desired elements.
The jQuery code looks like the following:
1 |
|
2 |
var $isAnimatedThird = $('.third .is-animated'), |
3 |
$isAnimatedThirdSingle = $('.third .is-animated__single'); |
4 |
|
5 |
/* this code is part of the onLeave callback */
|
6 |
if( ( index == 1 || index == 2) && nextIndex == 3 ) { |
7 |
$isAnimatedThird.eq(0).addClass('animated fadeInRightBig').css('animation-delay', '.3s'); |
8 |
$isAnimatedThird.eq(1).addClass('animated fadeInLeftBig').css('animation-delay', '.6s'); |
9 |
$isAnimatedThirdSingle.addClass('animated bounceInDown').css('animation-delay', '1.2s'); |
10 |
}
|
11 |
In this section, we use the fadeInRightBig and fadeInLeftBig animations to sequentially show the images. Furthermore, we show the button using the bounceInDown animation.
Animation #3
The fourth section consists of three elements: two paragraphs and one button. See how it’s structured below:
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
Some text here |
7 |
|
8 |
|
9 |
Some text here |
10 |
|
11 |
|
12 |
Thank You! |
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
Once again, notice that we’ve given target elements the is-animated and is-animated__single classes.
Next, have a look at the associated jQuery code:
1 |
|
2 |
var $isAnimatedFourth = $('.fourth .is-animated'), |
3 |
$isAnimatedFourthSingle = $('.fourth .is-animated__single'); |
4 |
|
5 |
/* this code is part of the onLeave callback */
|
6 |
if( ( index == 1 || index == 2 || index == 3 ) && nextIndex == 4 ) { |
7 |
$isAnimatedFourth.addClass('animated zoomIn').css('animation-delay', '.6s'); |
8 |
$isAnimatedFourthSingle.addClass('animated lightSpeedIn').css('animation-delay', '1.2s') |
9 |
$isAnimatedFourthSingle.one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() { |
10 |
$(this).removeClass('lightSpeedIn').addClass('zoomOutDown'); |
11 |
});
|
12 |
}
|
13 |
Here, both paragraphs appear at the same time using the zoomIn animation. On the contrary, the button appears using the lightSpeedIn animation.
Moreover, the following code helps us detect when an animation ends:
1 |
|
2 |
$('#yourElement').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', doSomething); |
3 |
In our example, we show the button only for a few seconds and then we take advantage of the aforementioned code to hide it.
Below you can see the embedded Codepen demo (though the full page demo is far more effective):
Conclusion
In this quick tip, we learned how we can combine the fullpage.js and animate.css libraries to build scroll-based animations.
If you want to improve this demo, here are two things you might want to try:
- Enable the animations only on large screens. To achieve this, use the
matchMediamethod. - Make the code within the
onLeavefunction more reusable.



