当前位置: 首页 > news >正文

动手吧,vue数字动画

数字动画,有数字的地方都能用上,拿去吧!

效果:

1、template部分

<template><div class="v-count-up">{{ dispVlaue }}</div>
</template>

2、js部分

export default {data() {return {timer: "",calcValue: 0,startTime: 0,remaining: 0,raf: "",};},props: {value: Number,startValue: {type: Number,default: 0,},time: {type: Number,default: 5000,},useease: {type: Boolean,default: true,},tofixed: {type: Number,default: 0,},separator: {type: Boolean,default: false,},reset: {type: Boolean,default: false,},},computed: {dispVlaue() {const calcValue = (this.calcValue || 0).toFixed(this.tofixed);return this.separator ? this.formatNumber(calcValue) : calcValue;},startVal() {return this.startValue > this.value ? this.value : this.startValue;},},created() {this.start();},watch: {reset() {this._reset();},},methods: {count(timestamp) {if (!this.startTime) {this.startTime = timestamp;}let progress = timestamp - this.startTime;this.remaining = this.time - progress;if (this.useease) {this.calcValue = this.easeOutExpo(progress,this.startVal,this.value - this.startVal,this.time);} else {this.calcValue =this.startVal + (this.value - this.startVal) * (progress / this.time);}if (this.calcValue > this.value) {this.calcValue = this.value;}if (progress < this.time) {this.raf = requestAnimationFrame(this.count);} else {this.$emit("end");cancelAnimationFrame(this.raf);}},start() {if (this.time > 0) {this.raf = requestAnimationFrame(this.count);} else {this.printValue();}},_reset() {this.startTime = 0;this.calcValue = 0;this.remaining = 0;this.start();},easeOutExpo(t, b, c, d) {return (c * (-Math.pow(2, (-10 * t) / d) + 1) * 1024) / 1023 + b;},printValue() {this.calcValue = this.value;},formatNumber(num) {var result, x, x1, x2, x3;result = String(num);x = result.split(".");x1 = x[0];x2 = x.length > 1 ? "." + x[1] : "";if (this.separator) {x3 = "";for (var i = 0, len = x1.length; i < len; ++i) {if (i !== 0 && i % 3 === 0) {x3 = "," + x3;}x3 = x1[len - i - 1] + x3;}x1 = x3;}return x1 + x2;},},destroyed() {cancelAnimationFrame(this.raf);},
};

http://www.lryc.cn/news/172729.html

相关文章:

  • Android12之仿Codec2.0实现传递编解码器组件本质(四十六)
  • MongoDB【部署 04】Windows系统实现MongoDB多磁盘存储
  • ruoyi框架使用自定义用户表登录
  • 计算机视觉与深度学习-卷积神经网络-卷积图像去噪边缘提取-卷积-[北邮鲁鹏]
  • JS手动实现发布者-订阅者模式
  • 【含面试题】MySQL死锁日志分析与解决的Java代码实现
  • 解决方案:TSINGSEE青犀+智能分析网关助力智慧仓储智能化监管
  • 进程间通信
  • Ubuntu 22.04.3 LTS安装
  • 记一次manjaro-i3系统sogoupinying候选词无法正常显示中文(变方框了)问题解决方案
  • Lua学习笔记:词法分析
  • flask服务鉴权
  • 【2023华为杯B题】DFT类矩阵的整数分解逼近(思路及代码下载)
  • 基于微信小程序的校园生活管理系统设计与实现(源码+lw+部署文档+讲解等)
  • SQL server 创建存储过程
  • 一文了解亚马逊云科技适用于 Amazon Lightsail 的托管数据库
  • 【antd Col】奇怪的TypeError: Cannot read properties of undefined (reading ‘then‘)
  • requests处理 multipart/form-data 请求以及 boundary值问题
  • FBX文件结构解读【文本格式】
  • JS基础语法
  • 【Zabbix监控一】zabbix的原理与安装
  • 图的十字链表存储结构
  • 精华回顾:Web3 前沿创新者在 DESTINATION MOON 共话未来
  • 【RPC】gRPC 安装及使用
  • Pygame中Sprite类的使用3
  • 23年下考前须知-软考中级信息安全工程师
  • 关于表单快速开发低代码技术平台的内容介绍
  • 比特币 ZK 赏金系列:第 1 部分——支付解密密钥
  • 【Python深度学习】深度学习中框架和模型的区别
  • MyBatis面试题(二)