The objective of fadeIn
is not "animate the opacity of the element", but make the transition from invisible to visible. By "invisible" I mean display: none
. The animation of opacity is just a ruse for the element to depart from opacity 0
(in fact invisible) up to its current opacity (whatever it is).
Like this example in jsFiddle shows, an initially hidden element will become "visible" (i.e. occupy screen space) when you use fadeIn
. But its final opacity will be that which it actually possesses (i.e., 0
). (another example, showing that the transition actually occurs, but does not go up to the 1
)
If you want a method that allows you to choose a final opacity - regardless of the element - try fadeTo
.
$("div").fadeTo(2000, 1); // tempo, opacidade final, callback
Example. Note that although the element is not initially invisible (i.e. without the display: none
), the transition of opacity is normally carried out.
Thank you Sergio. See my comment in the mgibsonbr reply, there I explain what confused me.
– bfavaretto
@bfavaretto, I also came across this problem a while ago and interestingly because the .fade('in') Mootools has the problem reversed. Fade to opacity and not to display.
– Sergio