Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does jQuery FadeIn know the used display mode?

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).

like image 458
Jeff Avatar asked Aug 24 '12 08:08

Jeff


People also ask

What is the syntax of jQuery fadeIn () method?

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.

Which of the following method is used to toggle between the fadeIn () method and fadeOut () method?

The fadeToggle() method toggles between the fadeIn() and fadeOut() methods. If the elements are faded out, fadeToggle() will fade them in.

Which of the following method accepts opacity as parameter in jQuery?

fadeIn() method animates the opacity of the matched elements.


1 Answers

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"

like image 180
Esailija Avatar answered Oct 05 '22 00:10

Esailija