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

手机微信网站怎么做怎么选择网站开发

手机微信网站怎么做,怎么选择网站开发,网站的空间是,网站建设制作合同这个CountTo组件npmjs里当然有大把的依赖存在#xff0c;不过今天我们不需要借助任何三方依赖#xff0c;造个轮子来手动实现这个组件。 通过研究其他count to插件我们可以发现#xff0c;数字滚动效果主要依赖于requestAnimationFrame 通过js帧来让数字动起来#xff0c;…这个CountTo组件npmjs里当然有大把的依赖存在不过今天我们不需要借助任何三方依赖造个轮子来手动实现这个组件。 通过研究其他count to插件我们可以发现数字滚动效果主要依赖于requestAnimationFrame 通过js帧来让数字动起来数字变化则是依赖于内部的easingFn函数来每次计算。 首先声明组件props类型 interface Props {/*** 动画开始的值*/start?: number;/*** 目标值*/end: number;/*** 持续时间*/duration?: number;/*** 是否自动播放*/autoPlay?: boolean;/*** 精度*/decimals?: number;/*** 小数点*/decimal?: string;/*** 千分位分隔符*/separator?: string;/*** 数字前 额外信息*/prefix?: string;/*** 数字后 额外信息*/suffix?: string;/*** 是否使用变速函数*/useEasing?: boolean;/*** 计算函数*/easingFn?: (t: number, b: number, c: number, d: number) number;/*** 动画开始后传给父组件的回调*/started?: () void;/*** 动画结束传递给父组件的回调*/ended?: () void; }除了end 是必要的其他都是可选参数。 所以我们需要给组件默认值防止没有参数时会报错。 同时写几个工具函数便于后面使用 export default function Index({end,start 0,duration 3000,autoPlay true,decimals 0,decimal .,separator ,,prefix ,suffix ,useEasing true,easingFn (t, b, c, d) (c * (-Math.pow(2, (-10 * t) / d) 1) * 1024) / 1023 b,started () {},ended () {}, }: Props) {const isNumber (val: string) {return !isNaN(parseFloat(val));};// 格式化数据返回想要展示的数据格式const formatNumber (n: number) {let val ;if (n % 1 ! 0) val n.toFixed(decimals);const x val.split(.);let x1 x[0];const x2 x.length 1 ? decimal x[1] : ;const rgx /(\d)(\d{3})/;if (separator !isNumber(separator)) {while (rgx.test(x1)) {x1 x1.replace(rgx, $1 separator $2);}}return prefix x1 x2 suffix;};... }初始化数据 const [state, setState] useStateState({start: 0,paused: false,duration,});const startTime useRef(0);const _timestamp useRef(0);const remaining useRef(0);const printVal useRef(0);const rAf useRef(0);const endRef useRef(end);const endedCallback useRef(ended);const [displayValue, setValue] useState(formatNumber(start));// 定义一个计算属性当开始数字大于结束数字时返回trueconst stopCount useMemo(() start end, [start, end]);动画的关键函数 const count (timestamp: number) {if (!startTime.current) startTime.current timestamp;_timestamp.current timestamp;const progress timestamp - startTime.current;remaining.current state.duration - progress;// 是否使用速度变化曲线if (useEasing) {if (stopCount) {printVal.current state.start - easingFn(progress, 0, state.start - end, state.duration);} else {printVal.current easingFn(progress, state.start, end - state.start, state.duration);}} else {if (stopCount) {printVal.current state.start - (state.start - endRef.current) * (progress / state.duration);} else {printVal.current state.start (endRef.current - state.start) * (progress / state.duration);}}if (stopCount) {printVal.current printVal.current endRef.current ? endRef.current : printVal.current;} else {printVal.current printVal.current endRef.current ? endRef.current : printVal.current;}setValue(formatNumber(printVal.current));if (progress state.duration) {rAf.current requestAnimationFrame(count);} else {endedCallback.current?.();}};执行动画的函数 const startCount () {setState({ ...state, start, duration, paused: false });rAf.current requestAnimationFrame(count);startTime.current 0;};挂载时监听是否有autoPlay 来选择是否开始动画同时组件销毁后清除requestAnimationFrame动画 useEffect(() {if (autoPlay) {startCount();started?.();}return () {cancelAnimationFrame(rAf.current);};}, []);一些相关依赖的监听及处理 useEffect(() {if (!autoPlay) {cancelAnimationFrame(rAf.current);setState({ ...state, paused: true });}}, [autoPlay]);useEffect(() {if (!state.paused) {cancelAnimationFrame(rAf.current);startCount();}}, [start]);最后返回displayValue就可以了 好了 我要开启五一假期了 最后附上完整代码 – use client;import { useEffect, useMemo, useRef, useState } from react;interface Props {/*** 动画开始的值*/start?: number;/*** 目标值*/end: number;/*** 持续时间*/duration?: number;/*** 是否自动播放*/autoPlay?: boolean;/*** 精度*/decimals?: number;/*** 小数点*/decimal?: string;/*** 千分位分隔符*/separator?: string;/*** 数字前 额外信息*/prefix?: string;/*** 数字后 额外信息*/suffix?: string;/*** 是否使用变速函数*/useEasing?: boolean;/*** 计算函数*/easingFn?: (t: number, b: number, c: number, d: number) number;/*** 动画开始后传给父组件的回调*/started?: () void;/*** 动画结束传递给父组件的回调*/ended?: () void; } interface State {start: number;paused: boolean;duration: number; } export default function Index({end,start 0,duration 3000,autoPlay true,decimals 0,decimal .,separator ,,prefix ,suffix ,useEasing true,easingFn (t, b, c, d) (c * (-Math.pow(2, (-10 * t) / d) 1) * 1024) / 1023 b,started () {},ended () {}, }: Props) {const isNumber (val: string) {return !isNaN(parseFloat(val));};// 格式化数据返回想要展示的数据格式const formatNumber (n: number) {let val ;if (n % 1 ! 0) val n.toFixed(decimals);const x val.split(.);let x1 x[0];const x2 x.length 1 ? decimal x[1] : ;const rgx /(\d)(\d{3})/;if (separator !isNumber(separator)) {while (rgx.test(x1)) {x1 x1.replace(rgx, $1 separator $2);}}return prefix x1 x2 suffix;};const [state, setState] useStateState({start: 0,paused: false,duration,});const startTime useRef(0);const _timestamp useRef(0);const remaining useRef(0);const printVal useRef(0);const rAf useRef(0);const endRef useRef(end);const endedCallback useRef(ended);const [displayValue, setValue] useState(formatNumber(start));// 定义一个计算属性当开始数字大于结束数字时返回trueconst stopCount useMemo(() start end, [start, end]);const count (timestamp: number) {if (!startTime.current) startTime.current timestamp;_timestamp.current timestamp;const progress timestamp - startTime.current;remaining.current state.duration - progress;// 是否使用速度变化曲线if (useEasing) {if (stopCount) {printVal.current state.start - easingFn(progress, 0, state.start - end, state.duration);} else {printVal.current easingFn(progress, state.start, end - state.start, state.duration);}} else {if (stopCount) {printVal.current state.start - (state.start - endRef.current) * (progress / state.duration);} else {printVal.current state.start (endRef.current - state.start) * (progress / state.duration);}}if (stopCount) {printVal.current printVal.current endRef.current ? endRef.current : printVal.current;} else {printVal.current printVal.current endRef.current ? endRef.current : printVal.current;}setValue(formatNumber(printVal.current));if (progress state.duration) {rAf.current requestAnimationFrame(count);} else {endedCallback.current?.();}};const startCount () {setState({ ...state, start, duration, paused: false });rAf.current requestAnimationFrame(count);startTime.current 0;};useEffect(() {if (!autoPlay) {cancelAnimationFrame(rAf.current);setState({ ...state, paused: true });}}, [autoPlay]);useEffect(() {if (!state.paused) {cancelAnimationFrame(rAf.current);startCount();}}, [start]);useEffect(() {if (autoPlay) {startCount();started?.();}return () {cancelAnimationFrame(rAf.current);};}, []);return displayValue; }
http://www.tj-hxxt.cn/news/227720.html

相关文章:

  • 怎样把自己做的网站发到网上沪深300指数
  • 网站软件有哪些wordpress 设置头像
  • 周到的网站建设推广最强大的wordpress
  • 多种东莞微信网站建设php制作招聘网站
  • 中低端网站建设客户网wordpress评论邮箱通知
  • 网站维护是什么职业wordpress简单用户中心
  • 在线视频网站如何制作常用的设计网站有哪些
  • 从江网站建设河北省网络科技网站
  • 胶州做网站产品外观设计的重要性
  • 文创设计网站创意设计报告
  • 杭州做兼职网站建设宝安做棋牌网站建设哪家好
  • 做外贸网站要注意什么天使投资平台官网
  • 信息化建设包括网站建设有什么展厅设计做的好的网站
  • 路由器做php网站无法访问wordpress官网
  • 网站内容如何自动关联新浪微博合肥 做网站的
  • 网站模板登录模块seo怎么发布外链
  • 团购产品 网站建设结合公众号小店做网站
  • 网站开发备案费用五易网络
  • 郴州网站建设专业现状报告h5网站是什么意思
  • 网站模块分类seo专员工作内容
  • 新网站一天做多少外链成都网络营销推广公司哪家好
  • ps网站子页怎么做威海城乡建设局网站首页
  • 青岛网站排名提升检索网站怎么做
  • 怎么做国外的网站吗广州网站建设易企
  • 阿里巴巴网站建设方案兰州网站建设哪家好
  • 个人网站建设合同范本网站开发导航
  • 定制网站建设的释义wordpress 大神
  • 低价网站制作下载长沙app
  • 合肥网站建设兼职电子版简历word格式
  • 建立网站链接结构的基本方式有哪些广告代理发布平台