Skip to content

Commit dad78ff

Browse files
authored
update transitioning state example to use greensock (#1471)
1 parent 57f0c9e commit dad78ff

File tree

1 file changed

+20
-40
lines changed

1 file changed

+20
-40
lines changed

src/v2/guide/transitioning-state.md

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ All of these are either already stored as raw numbers or can be converted into n
1515

1616
## Animating State with Watchers
1717

18-
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):
18+
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/):
1919

2020
``` html
21-
<script src="https://cdn.jsdelivr.net/npm/tween.js@16.3.4"></script>
21+
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.3/TweenMax.min.js"></script>
2222

2323
<div id="animated-number-demo">
2424
<input v-model.number="number" type="number" step="20">
@@ -31,33 +31,23 @@ new Vue({
3131
el: '#animated-number-demo',
3232
data: {
3333
number: 0,
34-
animatedNumber: 0
34+
tweenedNumber: 0
35+
},
36+
computed: {
37+
animatedNumber: function() {
38+
return this.tweenedNumber.toFixed(0);
39+
}
3540
},
3641
watch: {
37-
number: function(newValue, oldValue) {
38-
var vm = this
39-
function animate () {
40-
if (TWEEN.update()) {
41-
requestAnimationFrame(animate)
42-
}
43-
}
44-
45-
new TWEEN.Tween({ tweeningNumber: oldValue })
46-
.easing(TWEEN.Easing.Quadratic.Out)
47-
.to({ tweeningNumber: newValue }, 500)
48-
.onUpdate(function () {
49-
vm.animatedNumber = this.tweeningNumber.toFixed(0)
50-
})
51-
.start()
52-
53-
animate()
42+
number: function(newValue) {
43+
TweenLite.to(this.$data, 0.5, { tweenedNumber: newValue });
5444
}
5545
}
5646
})
5747
```
5848

5949
{% raw %}
60-
<script src="https://cdn.jsdelivr.net/npm/tween.js@16.3.4"></script>
50+
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.3/TweenMax.min.js"></script>
6151
<div id="animated-number-demo" class="demo">
6252
<input v-model.number="number" type="number" step="20">
6353
<p>{{ animatedNumber }}</p>
@@ -67,33 +57,23 @@ new Vue({
6757
el: '#animated-number-demo',
6858
data: {
6959
number: 0,
70-
animatedNumber: 0
60+
tweenedNumber: 0
61+
},
62+
computed: {
63+
animatedNumber: function() {
64+
return this.tweenedNumber.toFixed(0);
65+
}
7166
},
7267
watch: {
73-
number: function(newValue, oldValue) {
74-
var vm = this
75-
function animate () {
76-
if (TWEEN.update()) {
77-
requestAnimationFrame(animate)
78-
}
79-
}
80-
81-
new TWEEN.Tween({ tweeningNumber: oldValue })
82-
.easing(TWEEN.Easing.Quadratic.Out)
83-
.to({ tweeningNumber: newValue }, 500)
84-
.onUpdate(function () {
85-
vm.animatedNumber = this.tweeningNumber.toFixed(0)
86-
})
87-
.start()
88-
89-
animate()
68+
number: function(newValue) {
69+
TweenLite.to(this.$data, 0.5, { tweenedNumber: newValue });
9070
}
9171
}
9272
})
9373
</script>
9474
{% endraw %}
9575

96-
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):
76+
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):
9777

9878
``` html
9979
<script src="https://cdn.jsdelivr.net/npm/tween.js@16.3.4"></script>

0 commit comments

Comments
 (0)