0

嗨,我想在 jquery 中添加延迟。我试图把$('.fade_test').delay(5000);它工作,但 div 后三个不是下一个开始的。

链接到jsfiddle

HTML

<div class="fadein">
<div class="fade_test">one <button id="toggler" class="playin">Pause</button></div>
<div class="fade_test">two <button id="toggler" class="playin">Pause</button></div>
<div class="fade_test">three <button id="toggler" class="playin">Pause</button></div>
</div>​

CSS

.fadein { position:relative; height:332px; width:500px; }
.fadein .fade_test { position:absolute; left:0; top:0; }

JS

var pauseplay;    

function startFader() {


    $x = $(".fade_test:visible").fadeOut(1000);
    $next = $x.next();
    if ($next.length == 0)
        $next = $(".fade_test:first-child");

    $next.fadeIn(1000);
    $('.fade_test').delay(5000);
}

function stopFader(){
    window.clearInterval(pauseplay);
console.log("stop");
}

   $('.fadein .fade_test:gt(0)').hide();

  pauseplay= window.setInterval(startFader, 2000);


var $button = $('.fadein #toggler');
$button.toggle(function() {
stopFader();  
$(this).toggleClass('playin pausin');
 $(this).text("Play");   
}, function() {

$(this).toggleClass('pausin playin');
 $(this).text("Pause");   
    pauseplay= window.setInterval(startFader, 2000);

});

非常感激任何的帮助

4

1 回答 1

0

不是 JQuery,但您可以使用 Javascript 非常简单的 setTimeout(fn,milliseconds);

是另一篇解释

function foo(){
   alert('foo');
}

setTimeout(foo,1000);
于 2012-11-15T15:18:14.170 回答