无法在某个点停止进度条
Not Able to Stop Progress Bar on Certain Point
>演示
使用jQuery进度条.js插件,我无法在任何某个时间点停止进度条。不幸的是,插件 api 没有解释如何做到这一点,但我试图通过声明一个存储进度值的目标变量来自己做到这一点。
target = bar.value();
然后我试图通过应用这样的 if 条件来停止进度
if ((target * 100).toFixed(0) == 60) {
circle.stop();
}
但这并不能阻止 60 的进度条!我尝试根据circle.stop();
函数使用它(如果您单击停止按钮,它会停止进度并提醒柱线(目标)的值,但 if 状态不起作用!
var target;
var circle = new ProgressBar.Circle('#container', {
color: '#FCB03C',
strokeWidth: 3,
trailWidth: 1,
duration: 1500,
bar: 60,
text: {
value: '0'
},
step: function (state, bar) {
bar.setText((bar.value() * 100).toFixed(0));
target = bar.value();
}
});
circle.animate(1, function () {
circle.animate();
})
if ((target * 100).toFixed(0) == 60) {
circle.stop();
}
$('#stop').on('click', function () {
circle.stop();
alert((target * 100).toFixed(0));
});
你能让我知道我做错了什么以及如何解决这个问题吗?谢谢
您的演示不起作用的原因是您只检查一次目标,当它刚刚声明时,没有任何值。 (undefined * 100).toFixed(0) == "NaN"
.由于 javascript 默认情况下不是反应性的,因此您必须在每次更新target
检查条件。step
函数非常适合此,因为每次值更改时都会调用它。要修复此错误,请移动:
if ((target * 100).toFixed(0) == 60) {
circle.stop();
}
内部step
功能:
step: function (state, bar) {
bar.setText((bar.value() * 100).toFixed(0));
target = bar.value();
if ((target * 100).toFixed(0) == 60) {
circle.stop();
}
}
固定演示。
相关文章:
- 没有找到相关文章