0

Hi I want to add delay in jquery. I was trying to put $('.fade_test').delay(5000); It is working but div last three is no next to start one.

Link to a 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);

});

Any help would be most appreciated

Ren
  • 1,111
  • 5
  • 15
  • 24
user692669
  • 23
  • 4

1 Answers1

0

Not JQuery but you could use Javascript's very simple setTimeout(fn,milliseconds);

here is another post explaining

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

setTimeout(foo,1000);
Community
  • 1
  • 1
adam
  • 2,930
  • 7
  • 54
  • 89