erezT erezT - 5 months ago 15
jQuery Question

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() {}

Answer

Try this

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

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