前端依赖11-“countup.js“: “^2.6.0“第一讲

一:简介

countup.js 是一个 JavaScript 库,用于在网页中创建动态的计数器效果。它可以让你在网页上展示数字逐渐增加的效果,通常用于统计、计时器或其他需要显示数字变化的场景。

二:官网

npm官网

github官网

三:常规JS使用

我在AI上了下,完整代码如下,结果不能用:

<!DOCTYPE html>
<html>
<head>
    <title>CountUp.js Example</title>
    <script src="https://cdn.jsdelivr.net/npm/countup.js"></script>
</head>
<body>
<h1>CountUp.js Example</h1>
<p>Count: <span id="myCounter"></span></p>

<script>
  var options = {
    startVal: 0,
    endVal: 100,
    duration: 3,
    separator: ','
  };
  var counter = new CountUp('myCounter', options);
  counter.start();
</script>
</body>
</html>

上述代码报错:
在这里插入图片描述

这个是什么原因呢?于是我从源代码入手,从源代码来看它的版本是 2.7.0
在这里插入图片描述

于是我研究了一下源码,并查看了一下文档,大概修改两个地方

  1. 参数中 endVal 现在已经不用了,正确方式为了 new countUp.CountUp('myCounter', 50000, options);
  2. 应该引用 dist/countUp.umd.js 而不是 dist/counter.js 文件,至于这是为什么,我目前也不太清楚

在这里插入图片描述

于是整理下来的代码如下:

<!DOCTYPE html>
<html>
<head>
    <title>CountUp.js Example</title>
    <script src="./demo/countUp.js/dist/countUp.umd.js"></script>
</head>
<body>
<h1>CountUp.js Example</h1>
<p>Count: <span id="myCounter"></span></p>

<script>
  var options = {
    startVal: 0,
    duration: 3,
    separator: ','
  };
  var counter = new countUp.CountUp('myCounter', 50000, options);
  counter.start();
</script>
</body>
</html>

正确的图示如下:
在这里插入图片描述

四:vue2的使用方式

明天再讲!今天不早了,要休息了!

五:vue3的使用方式

明天再讲!今天不早了,要休息了!

六: buildadmin的使用方式

明天再讲!今天不早了,要休息了!

简单看了一下,buildadmin中的 dashboard仪表盘 使用了这一方法!

明天再计!今天不早了,要休息了!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

岐伯漫谈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值