其他代码

svg-gauge 圆形进度条插件

阿里云


svg-gauge 是一款基于 SVG 的圆形进度条插件。该插件无任何依赖,可以轻松的制作出各种圆形进度条,以及圆形进度条的动画特效。

HTML 结构

最简单的按钮 HTML 结构如下。

也想出现在这里?联系我们
创客主机
  1. <div id="cpuSpeed" class="gauge-container"></div>

CSS 样式

  1. .gauge-container {
  2.   width: 150px;
  3.   height: 150px;
  4.   display: block;
  5.   padding: 10px;
  6. }
  7. .gauge-container > .gauge > .dial {
  8.   stroke: #eee;
  9.   stroke-width: 2;
  10.   fill: rgba(0,0,0,0);
  11. }
  12. .gauge-container > .gauge > .value {
  13.   stroke: rgb(47, 227, 255);
  14.   stroke-width: 2;
  15.   fill: rgba(0,0,0,0);
  16. }
  17. .gauge-container > .gauge > .value-text {
  18.   fill: rgb(47, 227, 255);
  19.   font-family: sans-serif;
  20.   font-weight: bold;
  21.   font-size: 1em;
  22. }

javaScript

  1. // npm install
  2. npm install svg-gauge
  3.  
  4. // Require JS
  5. var Gauge = require("svg-gauge");
  6.  
  7. // Standalone
  8. var Gauge = window.Gauge;
  9.  
  10. // Create a new Gauge
  11. var cpuGauge = Gauge(document.getElementById("cpuSpeed"), {
  12.     max: 100,
  13.     // custom label renderer
  14.     label: function(value) {
  15.       return Math.round(value) + "/" + this.max;
  16.     },
  17.     value: 50,
  18.     // Custom dial colors (Optional)
  19.     color: function(value) {
  20.       if(value < 20) {
  21.         return "#5ee432"; // green
  22.       }else if(value > 40) {
  23.         return "#fffa50"; // yellow
  24.       }else if(value > 60) {
  25.         return "#f7aa38"; // orange
  26.       }else {
  27.         return "#ef4655"; // red
  28.       }
  29.     }
  30. });
  31.  
  32. // Set gauge value
  33. cpuGauge.setValue(75);
  34.  
  35. // Set value and animate (value, animation duration in seconds)
  36. cpuGauge.setValueAnimated(90, 1);

Github 网址:https://github.com/naikus/svg-gauge

svg-gauge 圆形进度条插件

已有 377 人购买
  • 8p8v
查看演示升级 VIP立刻购买

演示地址 下载地址
收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!