English 中文(简体)
jquery .animate() in a loop using the Index on full:
原标题:jquery .animate() in a loop using the index on complete:

我正在撰写一封信,一劳永逸地进行多次估计,根据新的估算开始之时,目前估计的其余部分必须停下来,移至另一处(正在工作)。 因此,在添加新的估计时,我形成了一阵 an,每im一 complete,我需要从阵列中去除。 这里,我使用的是:

for (var i = 0; i < animations[key].length; i++) {
animations[key][i].object.animate({
    top: animations[key][i].endCoords.top,
    left: animations[key][i].endCoords.left
}, {
    duration: 800,
    complete: function() {
        console.log(i);
        animations[key].splice(i, 1);
        console.log(animations);
    }
});
}

问题在于何时完成:操作,i >,定在估算中。 我确信,我理解为什么这样做了,因为 lo在 an灭之前就仍在继续(这很好,因为它使我能够一劳永逸地进行多次估计),但是否有任何办法来写这部法典,这样,如果完成的话:它有正确的指数来做ice?

提前感谢!

问题回答

每种迭代使用/分配不同的变量应当做到:

for (var i = animations[key].length-1; i >= 0; i--) {
    var id = i;
    animations[key][id].object.animate({
        top: animations[key][id].endCoords.top,
        left: animations[key][id].endCoords.left
    }, {
        duration: 800,
        complete: function() {
            console.log(id);
            animations[key].splice(id, 1);
            console.log(animations);
        }
    });
}

否则,你将每次打上<代码>。

即便如此,你也不妨重新考虑你的做法:除非以他们开始的完全相同的顺序完成评估,否则你可能仍有麻烦!

edit:在广告方向上倒置(见以下注解),其副作用是开始反向的图像。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签