Performance of CSS Transitions vs. JS animation packages

JavascriptCssAnimation

Javascript Problem Overview


I'm wondering is there any difference in performance of using CSS Transitions vs. any of the various JavaScript animation libraries? (script.aculo.us, scripty2, jsAnim, MooTools, $fx, etc).

I've tried various tests in Safari and Chrome but I don't actually see any difference. I thought that CSS Transitions were supposed to be hardware accelerated.


Update:

I've tried using Scriptaculous' Effect.Fade on 5 different DIVs (each containing a canvas with some lines). Doing the exact same thing using CSS transitions, I see absolutely no difference in performance. Both were very smooth with one DIV/Canvas, but both are very slow when I do more than 2 at a time.

I've tried this in Safari 4, 5 (OSX), Google Chrome 5 and FireFox 3.7pre. Same results across the board.

In answer to UpHelix's response, you're not simply limited to hover, etc. You can trigger a transition by changing any transitionable style. For instance, set the opacity of an element in JavaScript (after, you've specified the transitionPropery and transitionDuration for that element).

Javascript Solutions


Solution 1 - Javascript

Yes, there is a difference, CSS is much faster. It may be difficult to see until you get many running at the same time or the more they do. CSS animations are limited though. In most cases they really only work off the :hover event. With JavaScript you can perform animations at any event: click, mouseover, mousemove, mouseout, keyup, keydown, etc.

In my opinion, jQuery is the best for JavaScript animations in 2010. See jQuery Demos

Solution 2 - Javascript

To add to Mechlar's (correct) answer: JavaScript is an interpreted language and the JS engine of the browser has to parse and execute every instruction during run-time (I know there exist JS compilers, like V8 (used in Chrome), but the principle remains the same).

On the other hand, browsers can implement CSS transitions natively, e.g. in C/C++ or something. This code will be compiled to machine language.

If CSS transitions are hardware accelerated or not, depends on the techniques the browser uses, the platform the browser runs on, etc.

Solution 3 - Javascript

You will notice the difference on mobile browsers (iPhone, Android, etc.).

Solution 4 - Javascript

CSS animations have the advantage of being processed by the browser. Fast computations and optimizations are available. In my opinion web animations performance should be looked trough a "holistic" point of view. After all an animation, in terms of FPS, can not be faster then the browser refresh.

The real performance level is given by the overall UI performance. A JS and a CSS animation can look similar. However CSS animations win since they do not block the UI thread.

Stoyan Stefanov wrote and demo how CSS animations are put out of the UI thread: http://www.phpied.com/css-animations-off-the-ui-thread/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondesauView Question on Stackoverflow
Solution 1 - JavascriptMechlarView Answer on Stackoverflow
Solution 2 - JavascriptMarcel KorpelView Answer on Stackoverflow
Solution 3 - JavascriptMournerView Answer on Stackoverflow
Solution 4 - JavascriptMirceaView Answer on Stackoverflow