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

快速迁移网站桂林生活网论坛

快速迁移网站,桂林生活网论坛,微网站开发系统,wordpress如何显示首页react ant-design实现数字对比动画效果:当新获取的数字比之前展示的数字多或少2时,显示“2”或“-2”的动画效果 1. 创建独立的 AnimatedValue 组件 // components/AnimatedValue/index.jsx import React, { useState, useEffect, useRef } from reac…

 react + ant-design实现数字对比动画效果:当新获取的数字比之前展示的数字多或少2时,显示“+2”或“-2”的动画效果

1. 创建独立的 AnimatedValue 组件

// components/AnimatedValue/index.jsx
import React, { useState, useEffect, useRef } from 'react';
import styles from './styles.module.less';const AnimatedValue = ({ value, name }) => {const [displayValue, setDisplayValue] = useState('--');const [diff, setDiff] = useState(null);const prevValue = useRef(null);const isInitialLoad = useRef(true);useEffect(() => {if (value !== undefined && value !== null) {const numValue = Number(value);// 只有在不是初始加载且前值存在时才计算差值if (!isInitialLoad.current && prevValue.current !== null) {const difference = numValue - prevValue.current;if (Math.abs(difference) >= 1) {setDiff(difference);// 3秒后清除差值显示const timer = setTimeout(() => setDiff(null), 3000);return () => clearTimeout(timer);}}prevValue.current = numValue;setDisplayValue(numValue);if (isInitialLoad.current) {isInitialLoad.current = false;}} else {setDisplayValue('--');}}, [value]);return (<div className={styles.value_container}><div className={styles.value}>{displayValue}</div>{diff !== null && (<div className={`${styles.diff_animation} ${diff > 0 ? styles.increase : styles.decrease}`}>{diff > 0 ? `+${diff}` : diff}</div>)}</div>);
};export default AnimatedValue;

2. 对应的样式文件

// components/AnimatedValue/styles.module.less
.value_container {position: relative;display: inline-block;min-width: 60px;height: 30px; // 固定高度防止布局抖动
}.value {display: inline-block;
}.diff_animation {position: absolute;right: -30px;top: 0;font-size: 14px;font-weight: bold;animation: fadeUp 1.5s ease-out forwards;will-change: transform, opacity;&.increase {color: #f5222d; // 红色表示增加}&.decrease {color: #52c41a; // 绿色表示减少}
}@keyframes fadeUp {0% {opacity: 1;transform: translateY(0);}70% {opacity: 1;}100% {opacity: 0;transform: translateY(-20px);}
}

3. 在父组件中使用

import React, { useState, useEffect } from 'react';
import { Row, Col } from 'antd';
import AnimatedValue from '@/components/AnimatedValue';
import styles from './yourStyles.module.less';const BusiMonitor = () => {const [data, setData] = useState([]);// 模拟API调用const fetchData = () => {// 模拟数据变化const newData = data.map(item => ({...item,value: Math.floor(Math.random() * 20)}));setData(newData);};// 设置定时器,每10秒调用一次APIuseEffect(() => {const timer = setInterval(fetchData, 10000);fetchData(); // 初始加载数据return () => clearInterval(timer);}, []);return (<Row justify="space-between">{data.map(({ name, value }, index) => (<Col ><div><div className={styles.name}>{name}业务量</div><AnimatedValue value={value} name={name} /></div></Col>))}</Row>);
};export default BusiMonitor;


文章转载自:

http://M1UqkmxU.nffwL.cn
http://FLvLnMhM.nffwL.cn
http://udPGwQqf.nffwL.cn
http://J3xfoxQj.nffwL.cn
http://BJlk1o2u.nffwL.cn
http://CMjgdHSe.nffwL.cn
http://2yl9IJEN.nffwL.cn
http://1ogrj3Ay.nffwL.cn
http://Jhh0iRJD.nffwL.cn
http://si07g4CT.nffwL.cn
http://S1y58MF4.nffwL.cn
http://W3xJURol.nffwL.cn
http://H3DO0Fyf.nffwL.cn
http://pDXRBiFE.nffwL.cn
http://CjQSWimY.nffwL.cn
http://ImMrurl5.nffwL.cn
http://AYax2eLW.nffwL.cn
http://1CFEbZX6.nffwL.cn
http://iMN8KHqk.nffwL.cn
http://Hov4gUXD.nffwL.cn
http://Jm684Z2m.nffwL.cn
http://eUbJSOL9.nffwL.cn
http://Pvkh1cmh.nffwL.cn
http://3iQlKKIi.nffwL.cn
http://SMwpt2OV.nffwL.cn
http://bqkgErWV.nffwL.cn
http://kk5BnHP1.nffwL.cn
http://e6slpBaS.nffwL.cn
http://R6c7rwtu.nffwL.cn
http://DXxCVLtT.nffwL.cn
http://www.dtcms.com/wzjs/602485.html

相关文章:

  • 杭州做网站一般多少钱评论回复网站怎么做的
  • 网站排名怎么做的网页制作教程 基础
  • 长春建设厅网站首页wordpress注册密码
  • 古玩网站源码wordpress 一键 样式
  • 国外做游戏评测的视频网站有哪些西部数码网站管理助手 绑定域名
  • 网站工程和网络工程有什么区别企业查查app下载
  • 可以建公司网站网站品牌建设
  • 怎么用手机制作手机网站中国114建材网
  • 东莞网站建设企业网站制作公司中
  • 做ppt做好的网站为什么两学一做进不去网站
  • 竹子建站加盟咨询深圳东门属于哪个区
  • 网站主页与导航栏的设计做数学题好的网站
  • 惠州酒店网站建设森普网站建设
  • 在线教育网站开发实例互联网保险的发展
  • 广州制作网站哪家专业营销策划咨询公司
  • 新闻发布系统网站模板百度域名查询
  • 电脑系统做的好的网站好公众号怎么制作合集
  • 哪个网站有淘宝做图的素材wordpress 4.0 安装
  • 建设音乐网站功能定位网站建设分金手指专业二七
  • 使用模板怎么建站wordpress模板网站模板
  • 公司网站如何建立2023二级建造师报名官网入口
  • 福州网站微信公众号建设电子商务网站步骤
  • 软件开发可以做网站么网站提供的服务
  • 如何做信用网站截图怎么制作一份自己的简历
  • 上海专业的网站建设公司哪家好动漫网站策划书
  • 推荐聊城做网站公司做网站费用怎么记账
  • 商城网站怎么做内链seo教程网
  • 中国建设银行网站会员可以改名网站建设的可用性
  • 网站开发好后要做什么在线培训系统搭建方案
  • 交易网站制度建设百度搜索引擎广告位的投放