Create animations on page scroll using CSS

Hi there, you probably seen this done many times on web sites before. You get to the site and as you scroll elements will animate in (ex bounce, fade in etc). Today we are going to learn how to do this quickly. For this tutorial we are going to use animate.css this file will have all of our animations already created and you can just pick the ones you want to use. The whole scroll magic will come from a small script called Wow.js  All you have to do is drop it into your page and you are done.

Final Result

 

See the Pen mejvpj

What we will use:

  • animate.css – can be downloaded here
  • wow.js – can be downloaded here

 

Setup

The reason we are using animate.css is because it comes pre built with almost all animations you can think of. For production i would suggest just copying only the animations that you are using out of the file to keep the size down. If you are just interested in fade animations (up, down, left, right etc) check out our CSS snippet with just fade animations.  Of course you can create your own animations as well.
We even have a tutorial on how to create animations on page load if you want to get your hands dirty and do it yourself.

First things first import our files:

We are using CloudFlare CDN services  (cdnjs.com which you should too to save on your bandwidth!) to load our files. If you are using WordPress make sure to load the js files appropriately (this makes sure the files won’t conflict with other things you might have going on). Just place this inside your functions.php file in your theme folder (again do this only if you are using WordPress)

Now we just need to add initialization of our script on to the html page itself:

If you are using WordPress you can add this to your footer.php or header.php file or inject it using a hook.
You are all done with the setup! If you are using a custom animation css  instead of animate.css then you have to tweak the above line and use an option flag to use a different animation trigger other than ‘animated’ (see the codepen source since it has that option)

All the hard work is now done. Now just add the appropriate CSS too items you want to animate on scroll.

Creating basic html

Let’s create basic html with boxes so we can see our example in action. All we have to do is add the class wow to items you want to animate on scroll as well as the animation you want to use example fadeInLeft . Class wow will trigger the animation that you have selected. So your div might look like this:

Next lets add quick css to style our box:

The final html should look like this:

That’s it!
The possibilities are endless! Just remember to not over do it. Share your experience in the comments, and where you think this technique is used the best.