English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The fadeTo() method gradually changes the opacity of the selected element to the specified opacity.
This method is similar tofadeIn()The method is similar, but this method cancels the hiding of the element and always fades in100% opacity.
Note: The fadeTo() method does not change the page layout (the selected element will still occupy the same space as before).
$(selector).fadeTo(duration, opacity, easing, callback)
Gradually decrease the opacity of the <div> element:
$("button").click(function(){ $("div").fadeTo(500, 0.2); });Test to see‹/›
Gradually change the opacity of the <div> element:
$("#btn1.click(function(){ $("div").fadeTo(1000, 0); }); $("#btn2.click(function(){ $("div").fadeTo(1000, 1); });Test to see‹/›
UsingcallbackParameters:
$("button").click(function(){ $("div").fadeTo(500, 0, function(){ alert("Opacity decreased!!!"); }); });Test to see‹/›
Parameter | Description |
---|---|
duration | A string or number specifying how long the fade in effect will last Possible values:
|
opacity | specifies the opacity of the fade in. It must be between 0.00 and1a number between .00 |
easing | (Optional) A string that specifies the speed of the element at different points in the animation. The default value is "swing" Possible values:
|
callback | (Optional) The fadeTo() method is completed, and the function called |