Howdy_McGee
Howdy_McGee

Reputation: 10645

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++;
}

Upvotes: 1

Views: 1073

Answers (2)

endoalir
endoalir

Reputation: 381

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);

Upvotes: 4

Garis M Suero
Garis M Suero

Reputation: 8169

You can try:

$('#new').fadeIn("slow", function() { 
      $(this).delay(500).fadeOut("slow").delay(500).fadeIn("slow").delay(500).fadeOut("slow"); 
});

In your code it will look like:

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

EDITED

Upvotes: 1

Related Questions