javascript - 具有动态值的半圆形进度条
解决方案
如果要在第一次绘制后动态更改值,则需要引用外部变量中的完整宽度。
这是使用变量的实现stepsize
:
var stepsize = 100;
var bar = new ProgressBar.SemiCircle(container, {
strokeWidth: 10,
color: '#7DD740',
trailColor: '#eee',
trailWidth: 10,
easing: 'easeInOut',
duration: 1400,
svgStyle: null,
text: {
value: '',
alignToBottom: false
},
// Set default step function for all animate calls
step: (state, bar) => {
bar.path.setAttribute('stroke', state.color);
var value = Math.round(bar.value() * stepsize);
if (value === 0) {
bar.setText('');
} else {
// put here database value eg. 8/10
bar.setText(value + "/" + stepsize);
}
bar.text.style.color = state.color;
}
});
bar.text.style.fontFamily = '"Raleway", Helvetica, sans-serif';
bar.text.style.fontSize = '2rem';
// put here percente logic out put
bar.animate(0.6); // Number from 0.0 to 1.0
setTimeout(function() {
stepsize = Math.ceil(22);
bar.animate(0.5); // Number from 0.0 to 1.0
}, 3 * 1000);
#container {
width: 200px;
height: 100px;
}
#container2 {
width: 200px;
height: 100px;
}
svg {
height: 80px;
width: 100px;
fill: none;
stroke: #7DD740;
stroke-width: 10;
stroke-linecap: round;
-webkit-filter: drop-shadow( -3px -2px 5px gray);
filter: drop-shadow( -3px -2px 5px gray);
}
<link href="css/plugins/c3/c3.min.css" rel="stylesheet">
<script src="https://rawgit.com/kimmobrunfeldt/progressbar.js/1.0.0/dist/progressbar.js"></script>
<link href="https://fonts.googleapis.com/css?family=Raleway:400,300,600,800,900" rel="stylesheet" type="text/css">
<div>
<b>User's</b>
<div id="container"></div>
</div>
推荐阅读
- css - 尽管有变量,CSS Emotion 仍在缓存 CSS
- python - 如何使用树莓派上的串口打开/关闭继电器?
- java - 如何使用 selenium 下载 POST 响应文件
- c# - 如何在不同语言可能具有不同语法的情况下统一本地化字符串
- python - Django ModelForms - 如何为连接表设置默认值
- migration - DNN 遗留迁移产生“对象引用未设置为对象实例”
- javascript - 无法隐式转换 System.LINQ 存在显式转换您是否缺少演员表
- visual-studio-code - VS Code 不排除 Code 的 node_modules 被监视 - 文件监视限制已达到
- java - 如何解决Android上的应用程序安装错误“Package name null is not an installed package”
- nginx - 使用 nginx auth_basic + react app 找不到页面重新加载导致 404