• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
小码哥-倩倩
博客园    首页    新随笔    联系   管理    订阅  订阅

数字滚动组件

需求:需要制作一个数字滚动由0逐渐变大到具体的某个数值。
<template>
<div class="number-danwei">
{{curVal}}
</div>
</template>
<script>
export default {
name: "Button",
props:{
increaseNum:{
type:Number|String,
defalut:'',
},
},
data(){
return{
curVal:0,
}
},
methods:{
numberIncrease(startNum,maxNum){
var that = this;
let numText = startNum;
let golb; // 为了清除requestAnimationFrame
function numSlideFun(){ // 数字动画
numText+=1; // 速度的计算可以为小数 。数字越大,滚动越快
if(numText >= maxNum){
numText = maxNum;
cancelAnimationFrame(golb);
}else {
golb = requestAnimationFrame(numSlideFun);
}
that.curVal=numText
}
numSlideFun(); // 调用数字动画
}
},
mounted(){
this.numberIncrease(0,Number(this.increaseNum));
}
}
</script>
<style scoped>

</style>
posted @ 2019-05-17 09:44  小码哥-倩倩  阅读(217)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3