diff --git a/src/v2/guide/transitioning-state.md b/src/v2/guide/transitioning-state.md index 8f32acfb01..cbc3348ba7 100644 --- a/src/v2/guide/transitioning-state.md +++ b/src/v2/guide/transitioning-state.md @@ -15,10 +15,10 @@ All of these are either already stored as raw numbers or can be converted into n ## 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](https://github.com/tweenjs/tween.js): +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 [GreenSock](https://greensock.com/): ``` html - +
@@ -31,33 +31,23 @@ new Vue({ el: '#animated-number-demo', data: { number: 0, - animatedNumber: 0 + tweenedNumber: 0 + }, + computed: { + animatedNumber: function() { + return this.tweenedNumber.toFixed(0); + } }, watch: { - number: function(newValue, oldValue) { - var vm = this - function animate () { - if (TWEEN.update()) { - requestAnimationFrame(animate) - } - } - - new TWEEN.Tween({ tweeningNumber: oldValue }) - .easing(TWEEN.Easing.Quadratic.Out) - .to({ tweeningNumber: newValue }, 500) - .onUpdate(function () { - vm.animatedNumber = this.tweeningNumber.toFixed(0) - }) - .start() - - animate() + number: function(newValue) { + TweenLite.to(this.$data, 0.5, { tweenedNumber: newValue }); } } }) ``` {% raw %} - +

{{ animatedNumber }}

@@ -67,33 +57,23 @@ new Vue({ el: '#animated-number-demo', data: { number: 0, - animatedNumber: 0 + tweenedNumber: 0 + }, + computed: { + animatedNumber: function() { + return this.tweenedNumber.toFixed(0); + } }, watch: { - number: function(newValue, oldValue) { - var vm = this - function animate () { - if (TWEEN.update()) { - requestAnimationFrame(animate) - } - } - - new TWEEN.Tween({ tweeningNumber: oldValue }) - .easing(TWEEN.Easing.Quadratic.Out) - .to({ tweeningNumber: newValue }, 500) - .onUpdate(function () { - vm.animatedNumber = this.tweeningNumber.toFixed(0) - }) - .start() - - animate() + number: function(newValue) { + TweenLite.to(this.$data, 0.5, { tweenedNumber: newValue }); } } }) {% endraw %} -When you update the number, the change is animated below the input. This makes for a nice demo, but what about something that isn't directly stored as a number, like any valid CSS color for example? Here's how we could accomplish this with the addition of [Color.js](https://github.com/brehaut/color-js): +When you update the number, the change is animated below the input. This makes for a nice demo, but what about something that isn't directly stored as a number, like any valid CSS color for example? Here's how we could accomplish this with [Tween.js](https://github.com/tweenjs/tween.js) and [Color.js](https://github.com/brehaut/color-js): ``` html