2016-11-11 144 views
2

我构建了这个刮出了stackoverflow上的答案。我想才达到什么:。每个.children()元素延迟

对于每个.element.element-wrapper添加类.visible与延迟1000ms的

$('.element-wrapper').children('.element').each(function(i) { 
    var $item = $(this); 
    setTimeout(function() { 
    $('.element').addClass('visible'); 
    }, 1000 * i); 
}); 

回答

5

其实你差不多吧......只要改变下面一行,使其上下文当前包装敏感:

$('.element-wrapper').children('.element').each(function(i) { 
    var $item = $(this); 
    setTimeout(function() { 
    $item.addClass('visible'); // Change this line. 
    }, 1000 * i); 
}); 
+1

谢谢@Praveen为找过我的代码。最简单的东西有时是看不见的。 – Glockohnee

+0

@Glockohnee这是完全正确的......:D –