我需要在“每次”迭代之间设置延迟
if (index == 3) {
$$('.check').each(function (el, ind) {
if (ind > 0) {
$$('.check')[ind - 1].addClass('hide');
};
$$('.check')[ind].removeClass('hide'); /*here should come delay*/
});
}
请多多指教;)
最佳答案
正如 Sergio 所说,您可以在迭代中使用索引来实现级联效果。
(function(){
// don't always lookup through DOM, cache el references if they are
// not changing dynamically
var checks = $$('.check'),
index = 3;
// ...
if (index === 3){
checks.each(function(el, i){
// i truthy is enough.
i && checks[i-1].addClass('hide');
// use a 100ms incremental delay for each next el
this.delay(i*100, el, 'hide');
}, Element.prototype.removeClass);
}
}());
Function.prototype.delay
可以应用于 Element.prototype.removeClass
(用作有趣的上下文)。
请记住,以上内容已损坏 - 我们看不到您的所有代码或代码背后的意图。延迟应用的 removeClass
会起作用,但它稍后会撤消 addClass('hide')
,因此您最终会看到所有元素可见。
关于javascript - MooTools - "each"次迭代之间的延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30399661/