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);
You can't use the display property in CSS animations either.
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 .
One of the properties that cannot be animated is the display property.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With