我有来自progressbar.js的多个进度条,我想要销毁所有这些进度条。所有进度条名称都在列表中的字符串之后。例如,连接的用户是:User1,User2,John。然后将进度栏命名为:progressBarUser1,progressBarUser2,progressBarJohn。
socket.on('disconnect', function () {
console.log('Connection Lost');
socket.disconnect();
usersList.forEach(function(v) {
window["progressBar" + v.userID] = null; //Doesn't work
});
});
答案 0 :(得分:0)
将不同的进度条存储在变量中。确定变量在声明进度条和何时删除时都可用。然后在每个上使用.destroy()函数。
代码示例:
HTML:
<div id="line"></div>
<div id="circle"></div>
<div id="semicircle"></div>
使用Javascript:
var progressBars = [];
function addAnimations() {
progressBars.push(new ProgressBar.Line('#line'));
progressBars.push(new ProgressBar.Circle('#circle'));
progressBars.push(new ProgressBar.SemiCircle('#semicircle'));
progressBars.forEach(function(bar){
bar.animate(1.0);
});
}
function destroyAll() {
progressBars.forEach(function(bar){
bar.destroy();
});
}
addAnimations();
destroyAll();