Why is everyone missing this? JQuery is a library that provides a consistent API across browsers. In a future release couldn't they detect CSS3 animation support and update the animate function to use them if supported? Some projects are already doing this: http://www.benbarnett.net/2010/09/01/enhancing-jquerys-anima... Sounds like it should go into mainline jquery pretty soon.
jQuery or CSS3 transitions? Speed comparison + brief empirical explanation.
21–26 of 26 posts
Re: jQuery or CSS3 transitions? Speed comparison + brief empirical explanation.
#22Why is everyone missing this? JQuery is a library that provides a consistent API across browsers. In a future release couldn't they detect CSS3 animation support and update the animate function to use them if supported? Some projects are already doing this: http://www.benbarnett.net/2010/09/01/enhancing-jquerys-anima... Sounds like it should go into mainline jquery pretty soon.
Exactly - hopefully this will happen one day. Having used that plugin though it doesn't work perfectly on all code (jQuery Cycle + that for instance doesn't always work as expected). Any mention of transitions seems to result in a wontfix if you check through the jQuery bug tracker.
Keep in mind, the specs are rather large. When people talk about CSS "animations" there really talking about at least 3 specs, maybe 4. CSS 2D transforms, CSS 3D transforms, CSS transitions and CSS animation. There is a lot of work to get it right and tested in a nice JS wrapper, not to mention making it work with an existing JS based API.
Re: jQuery or CSS3 transitions? Speed comparison + brief empirical explanation.
#23I'd like to see a comparison between CSS3 and html5 canvas performance, as for a simple animation in this example, I think Canvas may be more applicable.
Re: jQuery or CSS3 transitions? Speed comparison + brief empirical explanation.
#24I did this same experiment with D3 (animating the outline-color and background-color for 1s with ease-in-out), and I got performance nearly identical to CSS. http://bl.ocks.org/d/1616423/ A lot of this gain is likely from using requestAnimationFrame, but there could be other optimizations in D3, such as a single timer loop for all transitions. So, I think it's misleading to say you can't do fast transitions in JavaSc…
http://stackoverflow.com/questions/8239235/smoothly-animate-...
But recently I went through Raphael's source an I saw an implementation on requestAnimationFrame, perhaps Mike can shed some light on what is different. Great work on d3.js by the way!
Re: jQuery or CSS3 transitions? Speed comparison + brief empirical explanation.
#25maybe i am not getting something here but isn't this obvious? native c++ will be faster than javascript (which also compiles to c++ (i believe?) but does not have hardware acceleration and is single threaded [in case of jquery atleast]). Libraries (like jquery) were made to fill in the gaps that css or js had. now that the gaps are filling up, jquery becomes a redundancy (atleast for basic animations like that of css…
This is part of a tutorial, the idea was to give some evidence for justifying the use of transitions where possible. It also might get more people to realise that jQuery isn't the answer to everything, and animation is definitely not one of it's strong points (right now anyway!)
Re: jQuery or CSS3 transitions? Speed comparison + brief empirical explanation.
#26The CSS transition is performing a single tween on a CSS rule; the div tags just inherit the result. The jQuery test is performing inline style tweens ... on every div! First of all you're performing redundant/duplicate calculations. Second of all, you're throwing away all performance gains you had by having shared css render style objects.
A better test would of been to update the style sheet via JS.