jQuery:在每个迭代器中使用时间延迟?

dMi*_*Mix 4 javascript jquery

我正在尝试创建一个旋转木马效果,每3秒自动循环一次.

    $(".headline_img").each(function(intIndex){
        setTimeout($(this).show(),3000);
    });
Run Code Online (Sandbox Code Playgroud)

超时延迟不起作用.

这将在dom加载后立即显示所有图像.这就像忽略了setTimeout函数一样.

我错过了什么?

注意:我用$(document).ready调用它,您认为这可能会影响它吗?

Her*_*key 5

setTimeout函数采用函数引用或字符串.您的代码会show立即为每个元素调用方法.我不确定这是否有效:

$(function () {
  var t = 3000, $debug = $('#result');
    $(".headline_img").each(function(){
      var $img = $(this);
        setTimeout($img.show.bind($img), t);
      t += 3000;
    });
});
Run Code Online (Sandbox Code Playgroud)
.headline_img { display: none; }
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="headline_img">One</div>
<div class="headline_img">Two</div>
<div class="headline_img">Three</div>
Run Code Online (Sandbox Code Playgroud)

但值得一试......