jQuery animate only animates css numeric values. It will not animate between classes (see the example below on how to do this). The .animate () function adds the css that you give it as a paramater, and adds it as the inline css. It will always override the CSS stylesheet. It's fine, but a little messy and can get out of hand very easily.
However, if you want to animate between classes, it is best to use performance and cleanup to use the css3 transition property. Example:
HTML
<div class="myTestAnimation">Something to test</div>
JQuery (you can use vanilla javascript for this). Just switching between classes. This way you have no style information at all in your css.
jQuery(document).ready(function($) { $(".myTestAnimation").click(function() { $(this).toggleClass("animate"); }); });
CSS (this animates the width, height and background color) .animate () will not animate the background color to add an extra bonus.
.myTestAnimation { width: 50px; height: 50px; background-color: red; -webkit-transition: background-color 300ms linear, width 300ms linear, height 300ms linear; transition: background-color 300ms linear, width 300ms linear, height 300ms linear; position: relative; } .myTestAnimation.animate { background-color: blue; width: 200px; height: 200px; }
source share