Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery每个循环:如何集成到进度条javascript代码中_Javascript_Jquery_Progress Bar - Fatal编程技术网

Jquery每个循环:如何集成到进度条javascript代码中

Jquery每个循环:如何集成到进度条javascript代码中,javascript,jquery,progress-bar,Javascript,Jquery,Progress Bar,我发现了一篇关于使用javascript创建进度条的精彩文章: 除了一段我无法集成的代码外,它对我来说非常有用 假设采用这种方法: var process = { steps: [ function(){ //processing }, function(){ //processing }, functi

我发现了一篇关于使用javascript创建进度条的精彩文章:

除了一段我无法集成的代码外,它对我来说非常有用

假设采用这种方法:

var process = {
steps: [
                function(){
                //processing
            },
            function(){
                //processing
            },
            function(){
                element.each(function(index){
                    //processing
                });
            },
            function(){
                //processing
            },
            function(){
                //processing
            }
],
index: 0,
nextStep: function(){
    this.steps[this.index++]();
    if (this.index != this.steps.length) {
        var me = this;
        window.setTimeout(function(){
            me.nextStep();
        }, 0);
    }
}
})

process.nextStep()

这很有效。然而,我有一个这样的过程:

element.each(function(index){
     //do some processing
});
function(){
     element.each(function(index){
          //do some processing
     });
},
集成此功能的一种方法是将其放入如下函数中:

element.each(function(index){
     //do some processing
});
function(){
     element.each(function(index){
          //do some processing
     });
},
然而,大约70%的处理是在这个循环中完成的。因此,如果进度条从10%跳到80%,它就有点违背了进度条的目的。我想做的是,在步骤部分中,将每个循环的每次迭代视为一个匿名函数。所以最终的目标是,除了将每个已经定义的函数计算为一个步骤之外,我的每个循环的每个迭代都将被计算为一个步骤,关于如何做到这一点有什么想法吗?我试着把每个循环都扔进去,但都没有成功


感谢您的帮助。

用于进度条的方法与用于每个步骤的方法不兼容。在该方法中,无法更新for each执行的步骤的每个部分的进度条。最好使用不同的方法更新进度条。

用于进度条的方法与用于每个步骤的方法不兼容。在该方法中,无法更新for each执行的步骤的每个部分的进度条。您最好使用不同的方法来更新进度条。

这有点不对劲,但您可以使用each()循环用处理步骤填充队列,然后执行该队列。在本例中,我使用一个空jQuery对象作为队列。setTimeout是对DOM进行可见更改所必需的

例如:

var myQueue = $({});    

element.each(function(index){
    myQueue.queue('stack', function() {
        //do some processing
        setTimeout(function() { myQueue.dequeue('stack'); }, 10);
   }
});
如果使用v1.4+,以上内容适用于jQuery 1.3:

var myQueue = $({});    

element.each(function(index){
    myQueue.queue('stack', function(next) {
        //do some processing
        setTimeout(function() { next(); }, 10);
   }
});
从每个循环生成并填充队列后,可以使用以下命令启动队列:

myQueue.dequeue('stack');

另请参见

这是一个小技巧,但您可以使用each()循环用处理步骤填充队列,然后执行该队列。在本例中,我使用一个空jQuery对象作为队列。setTimeout是对DOM进行可见更改所必需的

例如:

var myQueue = $({});    

element.each(function(index){
    myQueue.queue('stack', function() {
        //do some processing
        setTimeout(function() { myQueue.dequeue('stack'); }, 10);
   }
});
如果使用v1.4+,以上内容适用于jQuery 1.3:

var myQueue = $({});    

element.each(function(index){
    myQueue.queue('stack', function(next) {
        //do some processing
        setTimeout(function() { next(); }, 10);
   }
});
从每个循环生成并填充队列后,可以使用以下命令启动队列:

myQueue.dequeue('stack');

另见

你能举个例子吗?你能举个例子吗?