From 4751349a20014ee9477903c1bf6b47920348c0d3 Mon Sep 17 00:00:00 2001
From: Sarah Drasner
Preview:
- -{{ tweenedCSSColor }}
-+ See the Pen + Updating SVG by Vue (@Vue) + on CodePen. +
+ ## Organizing Transitions into Components @@ -237,5 +160,5 @@ Vue can help. Since SVGs are just data, we only need examples of what these crea Sarah Drasner demonstrates this in the demo below, using a combination of timed and interactivity-driven state changes: -See the Pen Vue-controlled Wall-E by Sarah Drasner (@sdras) on CodePen.
+See the Pen Vue-controlled Wall-E by Sarah Drasner (@sdras) on CodePen.
From 787721a6f2908baa7349ef44144837a5b6477353 Mon Sep 17 00:00:00 2001 From: Sarah Drasner@@ -84,13 +84,22 @@ Managing many state transitions can quickly increase the complexity of a Vue ins ``` ```js -// This complex tweening logic can now be reused between -// any integers we may wish to animate in our application. -// Components also offer a clean interface for configuring -// more dynamic transitions and complex transition -// strategies. -Vue.component('animated-integer', { - template: '{{ tweeningValue }}', +const app = Vue.createApp({ + data() { + return { + firstNumber: 20, + secondNumber: 40 + } + }, + computed: { + result() { + return this.firstNumber + this.secondNumber + } + } +}) + +app.component('animated-integer', { + template: '{{ fullVal }}', props: { value: { type: Number, @@ -102,55 +111,43 @@ Vue.component('animated-integer', { tweeningValue: 0 } }, - watch: { - value(newValue, oldValue) { - this.tween(oldValue, newValue) + computed: { + fullVal() { + return Math.floor(this.tweeningValue) } }, - mounted() { - this.tween(0, this.value) - }, methods: { - tween(startValue, endValue) { - var vm = this - function animate() { - if (TWEEN.update()) { - requestAnimationFrame(animate) - } - } - - new TWEEN.Tween({ tweeningValue: startValue }) - .to({ tweeningValue: endValue }, 500) - .onUpdate(function() { - vm.tweeningValue = this.tweeningValue.toFixed(0) - }) - .start() - - animate() - } - } -}) - -// All complexity has now been removed from the main Vue instance! -new Vue({ - el: '#example-8', - data() { - return { - firstNumber: 20, - secondNumber: 40 + tween(newValue, oldValue) { + gsap.to(this.$data, { + duration: 0.5, + tweeningValue: newValue, + ease: 'sine' + }) } }, - computed: { - result() { - return this.firstNumber + this.secondNumber + watch: { + value(newValue, oldValue) { + this.tween(newValue, oldValue) } + }, + mounted() { + this.tween(this.value, 0) } }) + +app.mount('#app') ``` -TODO: put in example +
+ See the Pen + State Transition Components by Vue (@Vue) + on CodePen. +
+ + +Now we can compose multiple states with these child components. It's exciting- we can use any combination of transition strategies that have been covered on this page, along with those offered by Vue's [built-in transition system](transitions.html). Together, there are very few limits to what can be accomplished. -Within child components, we can use any combination of transition strategies that have been covered on this page, along with those offered by Vue's [built-in transition system](transitions.html). Together, there are very few limits to what can be accomplished. +You can see how we could use this for data visualization, for physics effects, for character animations and interactions, the sky's the limit. ## Bringing Designs to Life From 91eae74ab8250f60fae2633162533684bcac4272 Mon Sep 17 00:00:00 2001 From: Sarah Drasner