vue获取的数值从0开始自动增加动画(记录)

1.html

2.methods

numAutoAnimationFn(targetEle,options){//targetEle 节点id  options 配置参数
      options = options || {}
      var domEle = document.getElementById(targetEle)
      var time = options.time || domEle.data('time')
      var finaNum = options.num || domEle.data('value')
      var regulator = options.regulator || 100
      var step = finaNum/(time/regulator)
      var count = 0
      var initial = 0
      var timer = setInterval(function(){
        count = count + step
        if(count >= finaNum){
          clearInterval(timer)
          count = finaNum
        }
        var t = Math.floor(count)
        if(t == initial){
          return
        }
        initial = t
        domEle.innerHTML = initial
      },30)
    },
//time 变化用时时长 num 最终值  regulator 调速器 改变数字变化的速度
this.numAutoAnimationFn('allshengval',{time:1500,num:12000,regulator:50})

你可能感兴趣的:(大数据,javascript,前端)