110 of 119 menu

The fadeOut method

The fadeOut method fades elements out. You can show elements using the fadeIn method, making them opaque.

Syntax

Show for a given time, 400ms by default:

.fadeOut(duration);

Time can be specified not only in milliseconds, but also using the keywords slow (600ms) and fast (200ms), the higher the value, the slower the animation:

.fadeOut('slow' or either 'fast');

If you do not specify parameters, there will be no animation, the elements will be hidden instantly:

.fadeOut();

You can also pass the smoothing function as the second parameter, and the callback function as the third parameter - it will be triggered after the animation is completed. Both parameters are optional:

.fadeOut(duration, [smoothing function], [callback-function office]);

You can pass various options to the method, in the form of a JavaScript object containing key:value pairs:

.fadeOut(options);

Such an object can pass the following parameters and functions - duration, easing, queue, specialEasing, step, progress, complete, start, done, fail, always. You can see the description of these parameters for the method animate. For example, let's set the duration and the smoothing function:

.fadeOut( {duration: 800, easing: easeInSine} );

Example

In the following example, when the #hide button is clicked, the element with #test will be hidden using the fadeOut method, and when the #show button is clicked, it will be shown using fadeIn. We will also set the speed to 1000ms:

<button id="hide">hide</button> <button id="show">show</button> <div id="test"></div> #test { width: 200px; height: 200px; background: green; color: white; margin-top: 10px; } $('#show').on('click', function() { $('#test').fadeIn(1000); }); $('#hide').on('click', function() { $('#test').fadeOut(1000); });

Example

And in the following example, after the animation ends, when the element #test is shown, we will display alert with the text '!', and when hidden, with the text '?':

<button id="hide">hide</button> <button id="show">show</button> <div id="test"></div> #test { width: 200px; height: 200px; background: green; color: white; margin-top: 10px; } $('#show').on('click', function() { $('#test').fadeIn(1000, function() { alert('!'); }); }); $('#hide').on('click', function() { $('#test').fadeOut(1000, function() { alert('?'); }); });

See also

  • method fadeIn,
    which smoothly reveals hidden elements by making them opaque
  • method hide,
    which smoothly hides elements
  • method slideUp,
    which smoothly hides elements
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline