javascript - MooTools - "each"次迭代之间的延迟

标签 javascript mootools delay

我需要在“每次”迭代之间设置延迟

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/

相关文章:

javascript - Mootools 1.3.1 : using fx. 变形不起作用?

javascript - 显示延迟加载动画

javascript - 如何触发延迟的 jQuery 事件?

dataTables.editable.js 的 JavaScript 未捕获类型错误

javascript - Mootools .addEvent 无法进入 ng-repeat?

Javascript | JSON 和数组

javascript - 将 onChange javascript 函数延迟足够长的时间,以便另一个 javascript 完成

javascript - 正则表达式新手。在所有结束标签后添加空格

javascript - 如何消除 CSS 中的文本闪烁?

javascript - 当一个对象从另一个对象复制时,为什么 Angular 不数据绑定(bind)数据?