0

こんにちは、jquery に遅延を追加したいと思います。私はそれを入れようとし$('.fade_test').delay(5000);ていましたが、div last three is no next to start one.

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 に答える