CountUp.js数字滚动插件

JavaScript013

CountUp.js数字滚动插件,第1张

创建 new CountUp("ID选择器", 开始值, 结束值, 小数位数, 只需时间, options对象)

options对象:{

    useEasing: true,      -----使用缓和

  useGrouping: true,      -----使用分组(是否显示千位分隔符,一般为 true)

  separator: ',',      -----分隔器(千位分隔符,默认为',')

  decimal: '.',     ----- 十进制(小数点符号,默认为 '.')

  prefix: '',    -----字首(数字的前缀,根据需要可设为 $,¥,¥ 等)

  suffix: ''     -----后缀(数字的后缀 ,根据需要可设为 元,个,美元 等

}

val.start()

三部分

设置options对象       创建CountUp    执行.start()

数字实现滚动的效果

<span id="num1">1000</span>

<script src="https://cdn.bootcss.com/countup.js/1.9.3/countUp.js"></script>

<script type="text/javascript">   

 var options = {     

 useEasing: true,      

useGrouping: true,      

separator: ',',      

decimal: '.', 

  }   

 var num1 = new CountUp('num1', 0, 1000, 0, 2.5, options)   

 if (!num1.error) {    

 num1.start()  

  } else {     

 console.error(num1.error) 

   }

</script>

//num1:目标元素的ID 

 //0:滚动开始的数字

//100:滚动结束的数字

//2.5 :完成整个效果的时间