Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use fadeIn with display=inline-block [duplicate]

I try to fadeIn a div which (should) have a display inline-block.
It seems the fadeIn method assumes only display=block.
Is there a way to change that behavior?

like image 455
Itay Moav -Malimovka Avatar asked Jul 16 '11 14:07

Itay Moav -Malimovka


4 Answers

If you use css()?

$("div").fadeIn().css("display","inline-block");
like image 137
Sotiris Avatar answered Nov 10 '22 17:11

Sotiris


From a combination of what I read above, this is the best I got:

    $(div).css({
        opacity: 0,
        display: 'inline-block'     
    }).animate({opacity:1},600);
like image 20
Itay Moav -Malimovka Avatar answered Nov 10 '22 19:11

Itay Moav -Malimovka


I'd suggest putting an extra element layer inside the inline-block element, and fading that in instead.

<div style='display:inline-block;'>
    <div id='fadmein'>....</div>
</div>

$('#fademein').fadeIn();

I know it's extra markup, but it's probably the most pragmatic solution to the problem.

The alternative would be to use JQuery's animate() method to change the opacity, rather than using fadeIn(). This would only change the opacity property; so the display property would be untouched.

like image 6
Spudley Avatar answered Nov 10 '22 17:11

Spudley


According to this question in the jQuery Forums, the suggested solution is to change its ´display´ property to block and floating it.

like image 1
Simeon Avatar answered Nov 10 '22 18:11

Simeon