Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using jquery how to use fadein, delay and then fadeout issue

Tags:

jquery

css

dhtml

I need to make something fadeIn, then stay there for a second and then fadeOut using JQuery.

I've tried this but it dosent work for some reason???

$('#' + uMessage).fadeIn("fast").fadeOut("slow");  // works
$('#' + uMessage).fadeIn("fast").delay(1000).fadeOut("slow");  // fails

any suggestions where im going wrong?

Many thanks!!!

like image 384
James Radford Avatar asked Sep 07 '10 14:09

James Radford


2 Answers

Your second approach should be fine actually, corresponding to the docs (http://api.jquery.com/delay/)

Another approach may be to use the callback function which is called when the fadeIn has finished:

$('#' + uMessage).fadeIn("fast", function() { $(this).delay(1000).fadeOut("slow"); });

just a guess

Edit:

If you can't use the delay() method, then you could try this one:

$('#' + uMessage).fadeIn("fast", function() { 
  c_obj = $(this);
  window.setTimeout(function() { $(c_obj).fadeOut("slow"); }, 1000); 
});

Here's an example: http://jsfiddle.net/KwWFR/

like image 137
sled Avatar answered Nov 15 '22 07:11

sled


Maybe try using a callback as specified in the API for FadeIn function. This will be called once the fade in is completed.

$('#' + uMessage).fadeIn("fast", function() {
  $(this).delay(1000).fadeOut("slow");
});
like image 38
Fermin Avatar answered Nov 15 '22 09:11

Fermin