In my opinion, jQuery animate slightly overestimated compared to the CSS3 transition , which performs such animation on any 2D or 3D property. I’m also afraid that leaving it in the browser and forgetting the layer with the JavaScript name may lead to a spare processor juice - especially when you want to blow up the animation. So I like animations that define style definitions, since you define functionality with JavaScript . The more presentations you enter in JavaScript, the more problems you will encounter later.
All you have to do is use addClass for the element you want to animate, where you set the class with CSS transition properties. You simply “activate” the animation , which remains implemented at a pure level of presentation .
.js
// with jQuery $("#element").addClass("Animate"); // without jQuery library document.getElementById("element").className += "Animate";
You can easily remove a class with jQuery or delete a class without a library .
.css
#element{ color : white; } #element.Animate{ transition : .4s linear; color : red; -webkit-transform : rotate(90deg); }
.html
<span id="element"> Text </span>
This is a quick and convenient solution for most use cases.
I also use this when I want to implement a different style (alternative CSS properties) and want to change the style on the fly using global .5s animation. I am adding a new class to BODY , having alternative CSS in a form like this:
.js
$("BODY").addClass("Alternative");
.css
BODY.Alternative #element{ color : blue; transition : .5s linear; }
This way you can apply different styles with animation without loading different CSS files. You use JavaScript only to set the class .
Dyin Aug 29 '13 at 12:15 2013-08-29 12:15
source share