繁体   English   中英

从progressbar.js销毁Progressbar

[英]Destroy progressbar from progressbar.js

我有来自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
       });
     });

将不同的进度条存储在变量中。 在声明进度条和要删除进度条时,请确保该变量均可用。 然后,对每一个使用.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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM