Howdy_McGee Howdy_McGee - 6 months ago 15
jQuery Question

Blink Text for so many seconds - then disappear

I'm trying to fade in / out text and then after so long stop the function. For the most part when a user comes online it should say that user is online, then disapear after awhile. Right now it just keeps going - no stopping point. How do I add a point to make the fadein/out function stop?

function newUser(){
$j('#new').text(content);
$('#new').fadeIn('slow', function() {
setTimeout("$('#new').fadeOut('slow');", 2000);
});
}


This function when called will fade in and out the content of
#new
but it doesn't have a stopping point. How can I add a stopping time for this function?

I've tried this to see if it would work - but it only runs once? I have
x
initiated in beginning of my script as 0.

while(x < 4){
$j('#new').fadeIn("slow", function() {
$j(this).delay(500).fadeOut("slow");
});
x++;
}

Answer

How about something like this?

function do_blink(elm, i){
  if(i<=0){return;}
  elm.fadeIn("slow", function(){
    $(this).delay(500).fadeOut("slow");
    do_blink(elm, --i);
  });
}

where you call it like this

do_blink($("#new"),5);