.each .children() 元素有延迟

.each .children() element with delay

我构建这个是为了在 Whosebug 上抓取答案。我想要实现的目标:

对于 .element-wrapper 中的每个 .element 添加 class .visible 延迟 1000 毫秒 .

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

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

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