Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animate CSS display

Tags:

Is there a way to animate the CSS display property in jQuery? I have the following:

$(".maincontent").css("display","block"); 

and want it to do something like this:

$(".maincontent").animate({"display": "block"}, 2500); 
like image 869
danyo Avatar asked Jul 25 '13 16:07

danyo


People also ask

Can display be animated in CSS?

You can't use the display property in CSS animations either.

Can display none be animated?

CSS can't natively animate transitions that use display: none . You can hack around this limitation by using a mix of visibility: hidden and height: 0 to make it "close enough." While these solutions are probably fine in most cases, it isn't quite the same as using display: none .

Can you animate display property?

One of the properties that cannot be animated is the display property.


1 Answers

Just use .show() passing it a parameter:

$(".maincontent").show(2500); 

Edit (based on comments):

The above code fades in the element over a 2.5 second span. If instead you want a 2.5 second delay and then want the element to display, use the following:

$(".maincontent").delay(2500).fadeIn(); 

If, of course, you want a delay and a longer fade, just pass the number of milliseconds desired into each method.

like image 160
Derek Henderson Avatar answered Oct 12 '22 18:10

Derek Henderson