Simple question: How does jQuery know what display mode an element should use when using fadeIn?
What I mean, is that it appears to use the proper display mode for any element that I fadeIn, even when I set display:none
initially in my CSS - images are using inline, divs are using block, etc.
I looked into the jQuery source code on GitHub, but I couldnt locate what I was looking for.
Reason I ask is because I am making a little plugin myself, using fade (but with Animate, since there is more than 1 property that needs animation).
The jQuery fadeIn() method is used to fade in a hidden element. Syntax: $(selector).fadeIn(speed,callback); The optional speed parameter specifies the duration of the effect.
The fadeToggle() method toggles between the fadeIn() and fadeOut() methods. If the elements are faded out, fadeToggle() will fade them in.
fadeIn() method animates the opacity of the matched elements.
It uses $.data
to store it:
console.log($._data( elem, "olddisplay" ));
The underscore means that it can access data that is not normally available through $.data
or $.fn.data
. Basically this is for internal use only and you should not touch it.
If the element is set to display:none
through CSS, and you fade it in, jQuery still knows to make it inline
etc. In this case, it uses the function
// Try to determine the default display value of an element
function css_defaultDisplay( nodeName ) {
Which would give "inline"
for a nodeName === "span"
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