erezT
erezT

Reputation: 186

jQuery: How to time an element's fadeOut while still in loop?

I am looping an element with opacity yet I would like to stop it after 4.8 sec after the document is loaded. The snippet of my loop is here:

var centor = $(".centeror");
centor.delay(1000);
function centorRun(){
    centor.animate({opacity:'1'}, 700);
    centor.animate({opacity:'0.2'}, 700, centorRun);

}
centorRun();

Every time I run $(".centeror").delay(5800).fadeOut(); both out of function and in function scope I get bad results, and I'm thinking delay is not the function I should be using, am I right?

PS centorRun is within the $("document").ready(function() {}

Upvotes: 0

Views: 97

Answers (3)

Ronan Lopes
Ronan Lopes

Reputation: 3398

Try setTimeOut instead of delay. Something like setTimeout(centorRun, 4800);

Upvotes: 1

Vitaly
Vitaly

Reputation: 1281

Toggle 2 funciton every 2 seconds

$(".centeror").toggle(
  function() {
    $(this).animate({opacity:'.3'});
  }, function() {
    $(this).animate({opacity:'1'});
  }
);

setInterval(function(){$(".centeror").trigger('click')}, 2000);

Upvotes: 1

Firefog
Firefog

Reputation: 3174

Try this

  setTimeout('$(".centeror").fadeOut()',5000);

Change the time 5000 as mil Second what you like best. 1 sec=1000

Upvotes: 1

Related Questions