How to Add CSS Animation to a Website Easily with Animate.css
With every growing new day web is evolving, people are coming out with lots of new ideas and stuff to attract billions of internet savvy people. Web 2.0, HTML 5 etc, all these things concepts have enhanced the user experience drastically. Many frontend web developers tend to add lots of dynamic content to their design to keep use interested. They have tons of JavaScript libraries available at their disposal to add dynamic content or to add css animation to a website.
In this article we will see one such library Animate.css that is purely based on css and supports tons of animation and transition effects. This library is created and maintained by Daniel Eden.
First things First – Get a Copy
You need to download the animation.css from its official site. You can grab a copy from here or you can check it on Github. The css file is only 56kb and its minified version is 40kb. So you are getting bunch of cool, fun, and cross-browser animations for you to use in your projects with minimal foot print.
What are the animations supported
As mentioned above you have tons of css animation that can be used for your project. The animations are categorized as below so you can choose the right one
- Attention Seekers – bounce, flash, flash etc
- Bouncing Entrances – bounceIn, bounceInDown etc
- Bouncing Exits – bounceOut, bounceOutUp etc
- Fading Entrances – fadeIn, fadeInDownBig etc
- Fading Exits – fadeOutDownBig, fadeOutLeftBig etc
- Flippers – flip, flipOutX etc
- Rotating Entrances – rotateInDownLeft, rotateInUpLeft etc
- Rotating Exits – rotateOutDownLeft, rotateOutUpRight etc
- Sliders – slideInLeft, slideOutUp etc
- Specials – hinge, rollOut etc
Usage
The library provides you one of the easiest way to add animation. You only need to include the animation.css and apply some animation class to any element you want to add animation to and you are done. When page loads you will get perfect animation.
Add css to your html as shown below
1 |
<link href="animate.css" rel="stylesheet"/> |
Then simply add the css class to element
1 2 3 4 |
<div id="animationSandbox" class="bounceInDown animated"> <h1>Animate CSS Demo</h1> <p class="lead">Use the buttons provided on right side to simulate the animation you want. Don't forget to explore all tabs.</p> </div> |
Now go and refresh your page, you have your animation added to your page. We have setup a demo of complete animations available from this library, which you can see here
The demo uses JQuery code to apply different css on each button click. On each click the Js code will retrive data-anim attrib and apply that animation to our element. You can see here how we can apply css class
HTML
1 2 3 4 5 6 7 8 9 |
<div class="tab-pane" id="Specials"> <div class="buttons-playground"> <button type="button" class="btn btn-default triggerAnimation" data-anim="hinge">hinge</button> <button type="button" class="btn btn-default triggerAnimation" data-anim="rollIn">rollIn</button> <button type="button" class="btn btn-default triggerAnimation" data-anim="rollOut">rollOut</button> <button type="button" class="btn btn-default triggerAnimation" data-anim="lightSpeedIn">lightSpeedIn</button> <button type="button" class="btn btn-default triggerAnimation" data-anim="lightSpeedOut">lightSpeedOut</button> </div> </div> |
JQuery
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script> function testAnim(x) { jQuery('#animationSandbox').removeClass().addClass(x + ' animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){ jQuery(this).removeClass(); }); }; jQuery(document).ready(function(){ jQuery('.triggerAnimation').click(function(){ var anim = jQuery(this).attr("data-anim"); testAnim(anim); }); }); </script> |
gotta love this post:) Thanks! Saves a lot of time, especially with low paying customers who want some dynamics!
Thanks Pavan! great post! I just started to work with animate.css, so this comes in very handy! thanks again!