将百分比/进度值显示为仪表 圈进度

  • 源码大小:312.24KB
  • 所需积分:1积分
  • 源码编号:19JP-3570
  • 浏览次数:1056次
  • 最后更新:2023年06月27日
  • 所属栏目:加载
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

另一个圆形进度条插件,用于在响应式、可自定义的动画百分比/进度图中显示任何数值:圆形、环形图、饼图等。

更多功能:

  • 通过JavaScript和CSS进行完全自定义。
  • 基于SVG的矢量形状。
  • 顺时针或逆时针旋转。
  • 具有轻松功能的花式填充动画。
  • 6种数值显示模式。
  • 也可以用作普通的JavaScript插件。

参见:

  • 最佳循环/径向进度条JavaScript插件

如何使用它:

1.在文档中加载Circle Progress插件的脚本。要将Circle Progress用作jQuery插件,请确保加载jquery.circle-progress.min.js查询在最新的jQuery JavaScript库之后。

  1. <!-- Vanilla JavaScript -->
  2. <script src="dist/circle-progress.min.js"></script>
  3.  
  4. <!-- jQuery -->
  5. <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
  6. <script src="dist/jquery.circle-progress.min.js"></script>

2.创建一个空容器来容纳百分比/进度圆圈。

  1. <div class="progress"></div>

3.初始化插件并指定当前/最大值,如下所示:

  1. // Vanilla JavaScript
  2. new CircleProgress('.progress', {
  3. max: 100,
  4. value: 50
  5. });
  6.  
  7. // jQuery
  8. $('.progress').circleProgress({
  9. max: 100,
  10. value: 50
  11. });

4.使用以下CSS类自定义百分比/进度圆的样式。

  1. .circle-progress-svg {
  2. /*
  3. width: 200px;
  4. height: auto;
  5. ...
  6. */
  7. }
  8.  
  9. .circle-progress-circle {
  10. /*
  11. stroke-width: 6px;
  12. stroke: hsl(39, 100%, 85%);
  13. ...
  14. */
  15. }
  16.  
  17. .circle-progress-value {
  18. /*
  19. stroke-width: 6px;
  20. stroke: hsl(39, 100%, 50%);
  21. ...
  22. */
  23. }
  24.  
  25. .circle-progress-text {
  26. /*
  27. fill: hsl(39, 100%, 50%);
  28. ...
  29. */
  30. }
  31.  
  32. .circle-progress-text-value {
  33. /*
  34. fill: red;
  35. ...
  36. */
  37. }
  38.  
  39. .circle-progress-text-max {
  40. /*
  41. fill: red;
  42. ...
  43. */
  44. }

5.设置值的文本表示形式:

  • 水平(默认)
  • 竖的
  • 百分比
  • 价值
  • 圆圈上的值
  • 没有一个
  1. new CircleProgress('.progress', {
  2. textFormat: 'horizontal'
  3. });

6.自定义填充动画。

  1. new CircleProgress('.progress', {
  2.  
  3. // linear, easeInQuad, easeOutQuad, easeInOutQuad, easeInCubic, easeOutCubic, easeInOutCubic, easeInQuart, easeOutQuart, easeInOutQuart, easeInQuint, easeOutQuint, easeInOutQuint, easeInSine, easeOutSine, easeInOutSine, easeInExpo, easeOutExpo, easeInOutExpo, easeInCirc, easeOutCirc, easeInOutCirc, or none
  4. animation: 'easeInOutCubic',
  5.  
  6. // duration in milliseconds
  7. animationDuration: 600
  8. });

7.以度为单位设置起始角度。默认值:0。

  1. new CircleProgress('.progress', {
  2. startAngle: 45
  3. });

8.更多具有默认值的配置选项。

  1. new CircleProgress('.progress', {
  2. // min value
  3. min: 0,
  4.  
  5. // false = anti-clockwise
  6. clockwise: true,
  7.  
  8. // whether the value should be constrained between min and max
  9. constrain: true,
  10.  
  11. // indeterminate text
  12. indeterminateText, '?'
  13. });

更新日志:

版本0.2.4(2022-05-16)

  • 固定值OnCircle的文本值,并且没有动画

版本0.2.3(2022-03-13)

  • 错误修复

版本0.2.2(2022-01-16)

  • 支持NPM。

版本0.2.0(2020-08-23)

  • 添加UMD支持

版本0.1.2(2020-05-02)

  • 替换SVG innerHTML polyfill

版本0.1.1(2020-04-27)

  • 扩展动画功能

版本0.1.0(2019-10-05)

  • 将CSS类添加到SVG元素

预览截图