您的位置:首页 > Web前端 > JavaScript

countup.js实现数字动态叠加效果

2019-10-18 07:04 4179 查看

本文实例为大家分享了countup.js实现数字动态叠加效果的具体代码,供大家参考,具体内容如下

CountUp.js 无依赖的、轻量级的 JavaScript 类,可以用来快速创建以一种更有趣的动画方式显示数值数据。尽管它的名字叫 countUp,但其实可以在两个方向进行变化,这是根据你传递的 startVal 和 endVal 参数判断的。 再加上滚轮事件判断。

可配置的参数:

  • target = 目标元素的 ID;
  • startVal = 开始值;
  • endVal = 结束值;
  • decimals = 小数位数,默认值是0;
  • duration = 动画延迟秒数,默认值是2;

举例:

var options = {

  useEasing: true,
  useGrouping: true,
  separator: ',',
  decimal: '.',
};
var demo = new CountUp('myTargetElement', 0, 4068, 0, 2.5, options);
if (!demo.error) {
  demo.start();
} else {
console.error(demo.error);

安装:

npm i countup.js

在vue中使用:

<template>
<h1><span
ref='countup'
class="text"
></span>
</h1>
</template>

<script>
import { CountUp } from 'countup.js'
export default {
name: 'Countup',
data () {
return {
options: {
startVal: 1000
},
endCount: 2019
}
},
mounted () {
this.initCountUp()
},
methods: {
initCountUp () {
let demo = new CountUp(this.$refs.countup, this.endCount, this.options)
if (!demo.error) {
demo.start()
} else {
console.error(demo.error)
}
}
}
}
</script>

<style lang="less" scoped>
.text {
color: #4d63bc;
font-size: 16px;
}
</style>

演示地址:countUp.js

以上就是本文的全部内容,希望对大家的学习有所帮助

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  countup.js 数字 叠加