countup.js 数字动画

news/2025/2/19 17:30:02/

countup.js 数字动画

  • 1. 安装
  • 2. 参数
  • 3. Vue组件封装
    • 3.1 组件代码
    • 3.2 调用方式

1. 安装

npm i countup.js

2. 参数

项目Value
targetstring, HTMLElement ,HTMLInputElement - id of html element, input, svg text element, or DOM element reference where counting occurs
endValnumber - 最终数字
options?object选项对象

options 包含属性

{startVal?: number; // number to start at (0)decimalPlaces?: number; // number of decimal places (0)duration?: number; // animation duration in seconds (2)useGrouping?: boolean; // example: 1,000 vs 1000 (true)useIndianSeparators?: boolean; // example: 1,00,000 vs 100,000 (false)useEasing?: boolean; // ease animation (true)smartEasingThreshold?: number; // smooth easing for large numbers above this if useEasing (999)smartEasingAmount?: number; // amount to be eased for numbers above threshold (333)separator?: string; // grouping separator (',')decimal?: string; // decimal ('.')// easingFn: easing function for animation (easeOutExpo)easingFn?: (t: number, b: number, c: number, d: number) => number;formattingFn?: (n: number) => string; // this function formats resultprefix?: string; // text prepended to resultsuffix?: string; // text appended to resultnumerals?: string[]; // numeral glyph substitutionenableScrollSpy?: boolean; // start animation when target is in viewscrollSpyDelay?: number; // delay (ms) after target comes into viewscrollSpyOnce?: boolean; // run only onceonCompleteCallback?: () => any; // gets called when animation completesplugin?: CountUpPlugin; // for alternate animations
}

3. Vue组件封装

3.1 组件代码

<template><span ref="count" id="countupId" />
</template><script>
import { CountUp } from 'countup.js'
const defaultOptions = {startVal: 0,decimalPlaces: 2,duration: 1, useGrouping: true,useEasing: true, smartEasingThreshold: 999, smartEasingAmount: 333, // amount to be eased for numbers above threshold (333)separator: ',',decimal: '.' ,// decimal ('.')
}
export default {name: 'CountUp',props: {// 起始值endVal: {type: Number,default: 0},options: {type: Object,default: () => { }}},watch: {endVal() {if (this.$refs.count) {this.initCountUp()}}},mounted() {this.initCountUp()},methods: {initCountUp() {const coutOptions = Object.assign({}, defaultOptions, this.options)const countUp = new CountUp(this.$refs.count, this.endVal, coutOptions)countUp.start()}}
}
</script>

3.2 调用方式

  • 引入组件
import countUp from "@/components/numberAnimate";
  • 注册组件
 components: {countUp},
  • 使用组件
<count-up :end-val="Number(endVal)"/>

http://www.ppmy.cn/news/35825.html

相关文章

SAP 批量修改 工艺路线 和 BOM

1、在运维的过程中经常会遇到用户需要批量更改组件&#xff0c;或者是批量更改数量&#xff0c;还是组件里面的一些标识&#xff0c;当处理这些批量数据处理的业务时&#xff0c;BOM的批量更改一个想到的就是CS20&#xff0c;但是CS20当BOM需要替换的时候就不是很适用。新增的组…

js——proxy、Reflect中的receiver

proxy 一般情况 代码 let data{name:张三,age:12 } let proxyDatanew Proxy(data,{get(target,key,receiver){console.log(targetdata)console.log(receiverproxyData)console.log(targetreceiver)console.log(target,key,receiver)return target[key]},set(target,key,newV…

Baumer工业相机中偏振相机如何使用Baumer堡盟GAPI SDK来进行偏振数据的计算转换输出(C++)

项目场景 Baumer工业相机堡盟相机是一种高性能、高质量的工业相机&#xff0c;可用于各种应用场景&#xff0c;如物体检测、计数和识别、运动分析和图像处理。 Baumer的万兆网相机拥有出色的图像处理性能&#xff0c;可以实时传输高分辨率图像。此外&#xff0c;该相机还具…

react组件进阶(四)

文章目录1. 组件通讯介绍2. 组件的 props3. 组件通讯的三种方式3.1 父组件传递数据给子组件3.2 子组件传递数据给父组件3.3 兄弟组件4. Context5. props 深入5.1 children 属性5.2 props 校验5.3 props 的默认值6. 组件的生命周期6.1 组件的生命周期概述6.2 生命周期的三个阶段…

C++ 标准模板库-vector

文章目录1. 概念2. Construct&#xff08;构造&#xff09;3. destructor&#xff08;析构&#xff09;4. operator&#xff08;重载符号&#xff09;5. Capacity:6. 参考文献1. 概念 vector是一个序列化容器&#xff0c;相当于可以改变大小的数组。 2. Construct&#xff08…

SpringMVC的响应处理

文章目录一、传统同步业务数据响应1. 请求资源转发2. 请求资源重定向3. 响应模型数据4. 直接回写数据二、前后端分离异步业务数据响应一、传统同步业务数据响应 Spring响应数据给客户端&#xff0c;主要分为两大部分&#xff1a; ⚫ 传统同步方式&#xff1a;准备好模型数据&am…

mysql 8.0集群搭建(一主多从和多主多从)

MYSQL8.0集群搭建 一主多从 基础环境**1. 下载 mysql rpm包****2.主节点添加主从同步账户****3.开启二进制日志文件和添加server-id**4.登入主节点mysql重置偏移量5.注册从节点6.启动 启动所有从节点的slave7.多主多从模式&#xff0c;&#xff08;此模式基于上边一主多重模式搭…

为什么说学人工智能一定要学Python?

学习人工智能需要掌握大量的数据处理和算法实现&#xff0c;而Python作为一种高级编程语言&#xff0c;具有简单易学、灵活多变、开源丰富的库等优点&#xff0c;成为了人工智能领域广泛应用的语言之一。 具体来说&#xff0c;Python在人工智能中的优势包括&#xff1a; ​​…