.fadeIn()

Syntax and Description

$(selector).fadeIn([speed,] [easing,] [callback]);

displays the matched elements by fading them to opaque.

  • duration (optional)
    A string or number determining how long the animation will run
  • callback (optional)
    A function to call once the animation is complete

Its return value is the jQuery object, for chaining purposes.

The .fadeIn() method animates the opacity of the matched elements. Durations are given in milliseconds; higher values indicate slower animations. The 'fast' and 'slow' strings can be supplied to indicate durations of 200 and 600 milliseconds, respectively.

If supplied, the callback is fired once the animation is complete.

Fade in callback


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!--from w  w  w  . j  a  v a2  s .  c  o m-->
                  $("div").fadeIn(1000, function () {
                    alert("done");
                  });
        });
    </script>
  </head>
  <body>
    <body>
          <div style="display:none;">Click me</div>
    </body>
</html>

Click to view the demo

The code above generates the following result.

.fadeIn()

Fast fade in


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!--   ww  w  .  j a  v a2  s  .  c  om-->
                  $("div").fadeIn("fast");
        });
    </script>
  </head>
  <body>
    <body>
          <div style="display:none;">Click me</div>
    </body>
</html>

Click to view the demo

The code above generates the following result.

.fadeIn()

Fade in controlled by milliseconds


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!-- w w w.ja  va  2  s.  c  om-->
                  $("div").fadeIn(2000);
        });
    </script>
  </head>
  <body>
    <body>
          <div style="display:none;">Click me</div>
    </body>
</html>

Click to view the demo

The code above generates the following result.

.fadeIn()

Slow fade in


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!--from  w ww . j a v a 2  s  .  c o m-->
                  $("div").fadeIn("slow");
        });
    </script>
  </head>
  <body>
    <body>
          <div style="display:none;">Click me</div>
    </body>
</html>

Click to view the demo

The code above generates the following result.

.fadeIn()

Header fade in and fade out


<html>
<head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!--   w w w . jav a2 s. c om-->
              $("h1").css("opacity", 1).fadeIn(30).fadeOut(1000);
        });
    </script>
</head>
  <body>
       <div><h1>java2s.com</h1></div>
  </body>
</html>

Click to view the demo

The code above generates the following result.

.fadeIn()

Cascade fade out animation


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!--  w  w w .jav  a  2s  .  c om-->
            $("#info").fadeOut(800).fadeIn(800).fadeOut(400).fadeIn(400).fadeOut(400).fadeIn(400);
        });
    </script>
  </head>
  <body>
    <div style="" id="info">an animated info message</div>
  </body>
</html>

Click to view the demo

The code above generates the following result.

.fadeIn()
Home »
  Javascript Tutorial »
    jQuery Reference »
      Effect
Javascript Tutorial Effect
.animate()
.css() does animation
.clearQueue()
.delay()
.dequeue()
.extend()
.fadeIn()
.fadeOut()
.fadeTo()
.hide()
.queue()
.show()
.slideDown()
.slideToggle()
.slideUp()
.stop()
.toggle()