CSS Transition vs CSS Animation - css

Where is technical difference between CSS Transition and CSS Animation?
Is animation (with keyframes) consists of several transitions?
Is keyframes support the only difference?
Are both of them are hardware accelerated?

Are both of them are hardware accelerated?
-- Yes, both are hardware accelerated.
for other question answer you have to refer this site
https://cssanimation.rocks/transition-vs-animation/

Transition:
A transition is performed between two distinct states: A start state and an end state. Transitions also need a triggering event such as hover, focus and etc. Transitions are mostly used for simple animations.
Animation:
Unlike transitions, animations can be used for endless animations and have more than two states (#keyframes). They also have no boundaries.
Both use CPU acceleration for smoother effects.

Related

Perf css animation vs transition

I'd like to know what perf differences to expect from css animation (keyframes) vs css transition.
In my testing it seems there are situations where transition performs far better than keyframes. This article also suggests the same but it's from 2015 so thought it might be outdated https://www.pixelstech.net/article/1434375977-CSS3-animation-vs-CSS3-transition
Looking at MDN https://developer.mozilla.org/en-US/docs/Web/Performance/CSS_JavaScript_animation_performance
it states "In terms of performance, there is no difference between implementing an animation with CSS transitions or animations. Both of them are classified under the same CSS-based umbrella in this article."
So I'm surprised to see such as difference in testing. Maybe they're the same on firefox, but using Chrome I definitely see a difference.
I've made some tests on codesandbox to show animation jank with keyframes vs transition. Some important factors here:
1. I'm animating both transform and border-radius. I know you "shouldn't" animate border-radius, but this is part of the test.
2. When I combined the 2 tests into a SPA and toggled between them they both performed well, so it may be to do with page load.
To view the test in all its jankiness select 'mid-tier mobile' using chrome dev tools.
Janky css animation
https://codesandbox.io/s/perf-test-css-animation-nl6xs
Smooth css transition
https://codesandbox.io/s/perf-test-css-transition-fgd7w
Any help with this would be appreciated. I'm sure we can't fix it, but would like to know why keyframes sometimes has poor performance compared to transition.
Thanks!
Both seem like they should be pretty efficient animations as they are only composite changes (as they animate on scale which is efficient):
https://csstriggers.com/transform
I think the issue might be the fact that your test is not a "fair" comparison.
css animation (keyframes): This animation occurs straight away on the client browser. Also it's executing some more emotion code for keyframes.
css transition: This animations happens when React has completed its mount (as its done on a useEffect hook) and doesnt execute a keyframes function.
So the first css animation (keyframes) test might be effected by React taking precious resources away from the browser animation while it completes its lifecycle events.
Also the extra emotion keyframes call could slow it down - it makes another css call https://github.com/emotion-js/emotion/blob/6cb8d15438b01b8623af42f304d5ea3032332187/packages/core/src/keyframes.js#L11 so effectively you're calling css twice with the keyframes test.
Might be better to make a comparison in plain HTML + CSS so React or JS don't get in the way and give you false impression one is better than the other

angular 2 animation vs css animation - when to use what?

I'm currently trying out angular2's animation and I was wondering what specific advantage they bring over standard css animations/transitions.
e.g. a typical material designed card and hover effects with the box shadows. Most css frameworks use :hover and css-transitions. Is there a particular advantage in using angular 2 animations?
I read somewhere that some css animation properties don't invoke the GPU as much, hence there's somethings delays and lags. What about angular2 animations?
The question is actually more javascript animation vs css animation (because angular2's animations are based on javascript-animation).
The answer is that when you can - use CSS animation.
Modern browsers uses different thread for CSS animation, so the javascript-thread is not affected by the CSS animations.
You can use the HTML5 Animation Speed Test to check the preformance of different frameworks (javscript-based) VS CSS animation in your browser.
In general:
Browsers are able to optimize rendering flows. In summary, we should always try to create our animations using CSS transitions/animations where possible. If your animations are really complex, you can may have to rely on JavaScript-based animations instead.
If you want to know specifically regarding the Angular2 animations - just inspect the element in your browser and check if the animation there is a CSS(transition/animationFrame based or javascript (you will be able to see values in the style attribute change during the animation).
The answer is actually in the docs:
https://angular.io/guide/animations
Angular's animation system lets you build animations that run with the
same kind of native performance found in pure CSS animations. You can
also tightly integrate your animation logic with the rest of your
application code, for ease of control.
It also abstracts away the need to keep track of lengths of animations in order to stagger and avoid overloading the browser, or in chaining animations.
Generally, if you have a simple little thing, CSS is probably easier. But if you are consistently doing animation in your app you get a lot of power with little down-side from Angular Animations.

Unwanted delay in css3 animations triggered by adding classes

I am using the excellent css3 animations "library" provided by http://daneden.me/animate/
There is a slight but noticeable delay of about 1 second, when any of the examples are clicked. In the source it adds the animation-classes to the element and the browser will then execute the css animation statements.
I want the css3 animation to start immediately after clicking. Is there a solution?
You have the property animation-delay, this property wait x seconds, then start the animation.
I see animation-delay: .2s; on #animateTest.
Maybe you have good eyes to see this little time.

Hardware accelerated CSS3 animations VS transitions VS jQuery animate for mobile

I am developing an app using PhoneGap and jQuery, and am a little confused about animations.
I decided to go with what I already knew, which was jQuery animate, and this worked great, except I came across people talking about hardware acceleration.
All I am doing is animating a div to move right on page load:
$("#"+that).find('.captionShine img').animate({left: '550'},700);
I found a plugin called jQuery-Animate-Enhanced which turns these animations into CSS3 transitions, therefore hardware accelerating them (I believe).
So I looked more into the CSS3 animations, and am confused as to the difference between transitions and animations in CSS3. Can I still use hardware accleeration on the CSS3 animations? Or can it only be done on transform: translate3d(0,0,0);?
Is it just a case of assing translate3D to any element I want to have hardware accelerated?
kirupa has a very good explaination here: http://www.kirupa.com/html5/css3_animations_vs_transitions.htm
Skip down to read his conclusions bullet point first and then start reading from the top to fill in the details. Basically, transition and animation are two different way you define animation in css. Below is my own translation of the author conclusion.
Transition allow you to do very simple css that animate from a to b. Imagine you have an element with class="from-a" then you add a class to that element called class="to-b". Your transition definition in class="to-b" is where your animation ends.
Animation allow you to define/orchestrate the entire animation using keyframe css definition. Keyframes allow you to breakdown and orchestrate series of complex animations.
As you can see, because Transitions are based on adding of class or style to an element. You can easily define a series of classes and use with javascript+timeout to set these class and create the same kind of orchestration as Animation.

CSS3 animation: Number Count Up?

I'm trying to create a count-up animation using CSS3 that starts at a certain number "X" and counts up at a set interval by +1 using an animation sort of like this.
I know its possible to use the animation-duration line as the animation length, and just set the animation-iteration-count to infinite, but is it possible to make it load as "X+1" on each restart of the animation?
Thanks!
A thorough solution with many CSS-only options for counters is this!
It could maybe be done with a pseudo-element where you animate the content attribute, but support of CSS animations on pseudo-elements is still somewhat sketchy.
A JS-free solution would be to put the couting numbers actually in the HTML and then animate between those with
-webkit-animation-timing-function: steps(X);
Example here: JSFiddle
Depending on your feelings towards extra markup I would probably go with a JS solution (there's plenty out there).

Resources