14. Transitioning State

Transitioning State

Vue’s transition system offers many simple ways to animate entering, leaving, and lists, but what about animating your data itself? For example:

  • numbers and calculations
  • colors displayed
  • the positions of SVG nodes
  • the sizes and other properties of elements

All of these are either already stored as raw numbers or can be converted into numbers. Once we do that, we can animate these state changes using 3rd-party libraries to tween state, in combination with Vue’s reactivity and component systems.

Animating State with Watchers

Watchers allow us to animate changes of any numerical property into another property. That may sound complicated in the abstract, so let’s dive into an example using Tween.js:

<script src="https://unpkg.com/tween.js@16.3.4" rel="external nofollow"  rel="external