What is the difference between fadeIn
vs fadeOut
vs fadeTo
?
相关问题
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Include empty value fields in jQuery .serialize()
- Disable Browser onUnload on certain links?
- how to get selected text from iframe with javascri
I see only linguistic redundance here, since fadeTo fits all the use cases regardless.
fadeIn
fades from an elements current opacity to 1.fadeOut
fades from an elements current opacity to 0.fadeTo
fades from an elements current opacity to a given opacity.The above fades
myObject
from whatever opacity it has, to 0.5, which is 50% transparency, and after that, it fades up again to 20% transparency.FadeIn.. Shows an element gradually
FadeOut .. Hides an element gradually
FadeTo .. Changes the opacity of an element to a given value
Short Answer:
display
property, while animating fade.opacity
property, while animating fade.Long Answer:
fadeIn() and fadeOut() are both designed to control the
display
property, just like show() and hide(), but animating only a fade in between.Process of fadeIn()
opacity:0
.display:block
.opacity:1
.Process of fadeOut()
opacity:0
.display:none
.fadeTo() is meant to set the
opacity
property, while animating a fade in between.Process of fadeTo()
display: block
.opacity: [$]
.See the breakdown of formulas, which make up fadeIn() and fadeTo() on JsFiddle.
Update:
Closer relatives of fadeIn() and fadeOut() are rather show() and hide().
show() and hide() are also meant to control the
display
property, just like fadeIn()and fadeOut(), but in addition, animate width and height in between.Process of show()
opacity:0
,width:0
,height:0
display:block
opacity:1
,width:[auto]
,height:[auto]
Process of hide()
opacity:0
,width:0
,height:0
display:none
.Example:
Compare behavior of fadeIn(), fadeOut(), fadeTo(), show() and hide() on JsFiddle.