.each .children()元素有延迟

Glo*_*nee 2 javascript each jquery addclass function

我构建了这个在stackoverflow上的答案.我想要实现的目标:

对于每一个.element.element-wrapper添加类 .visible与延迟1000毫秒.

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

Pra*_*man 5

实际上你几乎是正确的...只需更改下面的一行,使其对当前包装器的上下文敏感:

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