<script src="https://unpkg.com/tween.js@16.3.4"></script>
<div id="app1">
<input v-model.number="number" type="number" step="20">
<p>{{animateNumber}}</p>
</div>
var app1 = new Vue({
el:'#app1',
data:{
number:0,
animateNumber:0
},
watch:{
number:function (newVal, oldVal) {
var vm = this
function animate() {
if (TWEEN.update()){
requestAnimationFrame(animate)
}
}
new TWEEN.Tween({tweeningNumber:oldVal})
.easing(TWEEN.Easing.Quadratic.Out)
.to({tweeningNumber:newVal}, 500)
.onUpdate(function () {
vm.animateNumber = this.tweeningNumber.toFixed(0)
})
.onComplete(function () {
cancelAnimationFrame(animate)
})
.start()
animate()
}
}
})
<script src="https://unpkg.com/tween.js@16.3.4"></script> <script src="https://unpkg.com/color-js@1.0.3/color.js"></script>
<div id="app-color">
<input v-model="colorQuery" @keyup.enter="updateColor" placeholder="Enter a color">
<button @click="updateColor">Update</button>
<p>Preview:</p>
<span :style="{backgroundColor:tweenedCSSColor}" class="color-preview">
</span>
<p>{{tweenedCSSColor}}</p>
</div>
var Color = net.brehaut.Color
new Vue({
el:'#app-color',
data:{
colorQuery:'',
color:{
red:0,
green:0,
blue:0,
alpha:1
},
tweenedColor:{}
},
created:function () {
this.tweenedColor = Object.assign({}, this.color)
},
watch:{
color:function () {
function animate() {
if (TWEEN.update()){
requestAnimationFrame(animate)
}
}
new TWEEN.Tween(this.tweenedColor)
.to(this.color, 750)
.start()
animate()
}
},
computed:{
tweenedCSSColor:function () {
return new Color({
red:this.tweenedColor.red,
green:this.tweenedColor.green,
blue:this.tweenedColor.blue,
alpha:this.tweenedColor.alpha
}).toCSS()
}
},
methods:{
updateColor:function () {
this.color = new Color(this.colorQuery).toRGB()
this.colorQuery = ''
}
}
})
<div id="app">
<input v-model.number="firstNumber" type="number" step="20"> +
<input v-model.number="secondNumber" type="number" step="20"> =
{{result}}
<p>
<animate-integer :value="firstNumber"></animate-integer> +
<animate-integer :value="secondNumber"></animate-integer> =
<animate-integer :value="result"></animate-integer>
</p>
</div>
Vue.component('animate-integer',{
template:'<span>{{tweeningValue}}</span>',
props:{
value:{
type:Number,
required:true
}
},
data:function () {
return {tweeningValue:0}
},
mounted:function () {
this.tween(0, this.value)
},
watch:{
value:function (newVal, oldVal) {
this.tween(oldVal, newVal)
}
},
methods:{
tween:function (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()
}
}
})
new Vue({
el:'#app',
data:{
firstNumber:20,
secondNumber:40
},
computed:{
result:function () {
return this.firstNumber + this.secondNumber
}
}
})
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有