views:

26

answers:

2

I can't seem to delay the showing of a div. I want to delay the animation by about 20 seconds is this possible???

$("#microcharcounter").delay(10000).show();
+1  A: 

Try this:

$("#microcharcounter").delay(10000).show(0);

or this:

$("#microcharcounter").delay(10000).queue(function(n) {
    $(this).show();
    n();
});

The reason for this is that .delay() will only delay items in an animation queue. So you can make .show() a short animation by adding a duration of '0', or add it to the queue with .queue().

patrick dw
If you manually queue, don't forget to dequeue! :)
Nick Craver
@Nick - Just added `n();`, but is it necessary when it is the last item?
patrick dw
@patrick - Yup, if you ever call another animation later for example, best to be safe IMO, alternatively you can call `$(this).show().dequeue()`, that's what I tend to do when dealing with `$(this)`, a bit cleaner to me anyway.
Nick Craver
@Nick - Ah, I see. Just did a test, and it does block the queue indefinitely. Thanks for the tip. :o)
patrick dw
+1  A: 

You can do it like this:

setTimeout(function() {
  $("#microcharcounter").show();
}, 20000);

The problem with .delay() and .show() (without a duration), is that .show() isn't an animation, it's an immediate effect that's not on the fx queue at all. You could however give it a duration, like this:

$("#microcharcounter").delay(20000).show("fast");
Nick Craver