JQuery: Start object as hidden in a way that allows .fadeIn() to work

Nate picture Nate · Sep 18, 2010 · Viewed 8.8k times · Source

I have an object that I want to start as hidden. I have tried to use each one of these styles one at a time. I have them in a class, not as inline styles.

display:none;

and

opacity:0;filter:alpha(opacity=0);

Now, these both worked obviously, the objects load hidden. The issue is that when I use these, the JQuery .fadeIn() function doesn't work. In fact, when I set the opacity to .5 (50), the fade in only fades in to .5 (50).

So what can I default the object to that will allow the .fadeIn() function to work?

Thanks!

Answer

Pramendra Gupta picture Pramendra Gupta · Sep 18, 2010

Hi is code with working version

HTML

<html>
    <body>
        <p>test</p>
    </body>
</html>

jquery​

$(document).ready(function() {
 $('p').fadeTo('slow', 1, function() {
      // Animation complete.
    });
});

CSS

p{
    display:none;
    opacity:0.0;
    filter:alpha(opacity=0);
}
​

live demo

http://jsfiddle.net/2p2v4/