tags:

views:

104

answers:

4

hi, 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!!!

+4  A: 

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/

sled
this doesnt work for me, any ideas?
James Radford
it works at least with jQuery v1.4.2: http://jsfiddle.net/D4eMb/1/
sled
I've added another solution
sled
+3  A: 

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");
});
Fermin
+1  A: 

I think the problem lies in the version of jQuery you use:

http://jsfiddle.net/b85hx/

This one works fine. Switch to 1.3.2 and it's broken.

Litso
im using v1.3.2
James Radford
In that case, update or go for @sled's solution
Litso
+1  A: 

Are you using jQuery 1.4+? The delay() function was added in jQuery 1.4

http://api.jquery.com/delay/

Sandro