Skip to content

Commit 338f2ea

Browse files
Alex-Sokolovchrisvfritz
authored andcommitted
Update transitioning-state.md (#996)
1 parent b506b23 commit 338f2ea

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

src/v2/guide/transitioning-state.md

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,17 @@ new Vue({
135135
},
136136
watch: {
137137
color: function () {
138-
var animationFrame
139-
function animate (time) {
140-
TWEEN.update(time)
141-
animationFrame = requestAnimationFrame(animate)
138+
function animate () {
139+
if (TWEEN.update()) {
140+
requestAnimationFrame(animate)
141+
}
142142
}
143+
143144
new TWEEN.Tween(this.tweenedColor)
144145
.to(this.color, 750)
145-
.onComplete(function () {
146-
cancelAnimationFrame(animationFrame)
147-
})
148146
.start()
149-
animationFrame = requestAnimationFrame(animate)
147+
148+
animate()
150149
}
151150
},
152151
computed: {
@@ -212,18 +211,17 @@ new Vue({
212211
},
213212
watch: {
214213
color: function () {
215-
var animationFrame
216-
function animate (time) {
217-
TWEEN.update(time)
218-
animationFrame = requestAnimationFrame(animate)
214+
function animate () {
215+
if (TWEEN.update()) {
216+
requestAnimationFrame(animate)
217+
}
219218
}
219+
220220
new TWEEN.Tween(this.tweenedColor)
221221
.to(this.color, 750)
222-
.onComplete(function () {
223-
cancelAnimationFrame(animationFrame)
224-
})
225222
.start()
226-
animationFrame = requestAnimationFrame(animate)
223+
224+
animate()
227225
}
228226
},
229227
computed: {
@@ -439,21 +437,20 @@ Vue.component('animated-integer', {
439437
methods: {
440438
tween: function (startValue, endValue) {
441439
var vm = this
442-
var animationFrame
443-
function animate (time) {
444-
TWEEN.update(time)
445-
animationFrame = requestAnimationFrame(animate)
440+
function animate () {
441+
if (TWEEN.update()) {
442+
requestAnimationFrame(animate)
443+
}
446444
}
445+
447446
new TWEEN.Tween({ tweeningValue: startValue })
448447
.to({ tweeningValue: endValue }, 500)
449448
.onUpdate(function () {
450449
vm.tweeningValue = this.tweeningValue.toFixed(0)
451450
})
452-
.onComplete(function () {
453-
cancelAnimationFrame(animationFrame)
454-
})
455451
.start()
456-
animationFrame = requestAnimationFrame(animate)
452+
453+
animate()
457454
}
458455
}
459456
})
@@ -510,21 +507,20 @@ Vue.component('animated-integer', {
510507
methods: {
511508
tween: function (startValue, endValue) {
512509
var vm = this
513-
var animationFrame
514-
function animate (time) {
515-
TWEEN.update(time)
516-
animationFrame = requestAnimationFrame(animate)
510+
function animate () {
511+
if (TWEEN.update()) {
512+
requestAnimationFrame(animate)
513+
}
517514
}
515+
518516
new TWEEN.Tween({ tweeningValue: startValue })
519517
.to({ tweeningValue: endValue }, 500)
520518
.onUpdate(function () {
521519
vm.tweeningValue = this.tweeningValue.toFixed(0)
522520
})
523-
.onComplete(function () {
524-
cancelAnimationFrame(animationFrame)
525-
})
526521
.start()
527-
animationFrame = requestAnimationFrame(animate)
522+
523+
animate()
528524
}
529525
}
530526
})

0 commit comments

Comments
 (0)