What is the difference between css and javascript animations?

8

Lately I've been studying some animations with CSS. However, by researching more about the subject, I ended up checking that it is possible to do animations also with javascript.

  • What's the difference?
  • Which is more feasible?

I know that CSS animations limit depending on the browser, so does JavaScript?

    
asked by anonymous 05.05.2015 / 20:55

1 answer

11

CSS3 , is not yet ready for professional-level animations on large, scalable projects. For simple things, - CSS3 is the winner, we can not even argue about it. If you are looking for animations mais robustas let's look at the following points:

1. The flow control

Imagine that you spent nights writing amazing, cutting-edge animation codes in pure CSS3. And now - here comes the hard part. You want to control them - pause, stop, go back, executed asynchronously, one after another, put in a timeline and time. Well, good luck with that. Literally, it is almost impossible. With javascript solutions (like GSAP) it's easy to make a pie! Write some lines of javascript code and you're good to go!

2. Animate multiple properties

Imagine you want to scale a div and in the middle of that animation, begin to rotate it and change the border color. You can not animate individual properties distinctly. However, JS-based solutions let you literally animate any numeric property in a variety of ways (just write animate for 50% of the initial width, animate for 0px, animate for -50px and then 150px). >

3. Organization

Code for larger projects can easily change and you may have to write complex animations, that's when the code organization is the key! With CSS3 it's almost impossible to group your animations into logical chunks to manage easily, just by calling methods and callbacks.

4. Compatibility

CSS3 transitions do not work in older browsers. And more - each browser handles them differently (and adds its own errors to your application). With few animations on your page it is probably easier to verify that everything runs smoothly, but it can become impossible once you go for a larger project. Javascript solutions provide an abstraction layer. You do not have to worry about browser-specific behaviors here's where the libraries are doing their job!

Conclusion

Is CSS animation "bad"? Certainly not! In fact, they are great for simple transitions between states (such as rollovers), when compatibility with older browsers is not required. CSS does transformations very well, and CSS animations can be very appealing to developers who prefer to put all of their animation and logical presentation in the CSS layer. However, JavaScript-based animation offers much more flexibility, better workflow for complex and interactively rich animations, and often performs as fast (or even faster) than CSS-based animation.

Summary:

css3:

  • Good point: fast
  • Negative point: Animation is primitive

js:

  • Good point: Animation (math) can have sophisticated methods, much more interactive for the user
  • Negative point: Some browsers can block js, it can be heavy, has time to load

In this site has a nice comparison, with animations, performance testing and a lot more! Take a look.

Font

    
05.05.2015 / 21:23