.slideDown()

Syntax and Description

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

All three arguments are optional. The speed, or duration of the animation, can be indicated as either a number (representing milliseconds) or as a string 'fast' or 'slow'.

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

A 'fast' animation is 200 milliseconds whereas a 'slow' animation is 600 milliseconds.

If the speed (aka duration) is omitted, the default speed is 400 milliseconds.

$.slideDown() accepts a callback function, which is executed once the $.slideDown() function has finished executing.

Slide down a paragraph


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!--from   www.ja  v a2 s  .  c  om-->
           $("div").one('click', function () {
              if ($(this).is(":first-child")) {
                $("p").text("It's the first div.");
              }else{
                $("p").text("It's NOT the first div.");
              }
              $("p").hide().slideDown("slow");
           });
        });
    </script>
     <style>
     div { border:2px white solid;}
  </style>

  </head>
  <body>
    <body>
      Press each to see the text.
      <div>java2s.com</div>
      <div>java2s.com</div>
      <div>java2s.com</div>
      <div>java2s.com</div>
      <div>java2s.com</div>
      <div>java2s.com</div>
      <p></p>
  </body>
</html>

Click to view the demo

The code above generates the following result.

.slideDown()

slideDown and slideUp

The following message shows the usage of slideDown and slideUp


<!DOCTYPE html>
<html>
<head>
<style type="text/css">
div {<!--from   w  ww . ja  va  2s . c om-->
  text-align: center;
  color: white;
  font-size: xx-large;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 50px;
  background-color: orange;
}
</style>
<script
  src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
  $(function() {
    $("div#message").click(function(e) {
      e.stopPropagation();
      $("div#message").slideUp('fast');
    });
    $(document).click(function() {
      $("div#message").slideDown('fast');
    });
  });
</script>
</head>
<body>
  <div id="message">This is a message.</div>
</body>
</html>

Click to view the demo

The code above generates the following result.

.slideDown()

Hide and Slide down


<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 va2s  . co m-->
                $("p").click(function () {
                    $("p").hide();

                    $("p").slideDown();
                });
        });
    </script>
  </head>
  <body>
    <body>
        <p>Hello java2s.com</p>
    </body>
</html>

Click to view the demo

The code above generates the following result.

.slideDown()

Slide down and set focus


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!-- w  ww .  ja va2 s  .co  m-->
               $("div").click(function () {
                  $("input").slideDown(1000,function(){
                     $(this).focus();
                  });
               });
        });
    </script>
    <style>
      input { display:none;margin:10px; }
    </style>
  </head>
  <body>
    <body>
          <div>Click me</div>
          <input type="text" />
          <input type="text"/>
          <input type="text" />
    </body>
</html>

Click to view the demo

The code above generates the following result.

.slideDown()

Slide down fast


<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 . ja  v a2s. c o  m-->
                $("p").click(function () {
                    $("p").hide();
                    $("p").slideDown("fast");
                });
        });
    </script>
  </head>
  <body>
    <body>
        <p>Hello java2s.com</p>
    </body>
</html>

Click to view the demo

The code above generates the following result.

.slideDown()

Slide down slowly


<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. co m-->
                $("p").click(function () {
                    $("p").hide();
                    $("p").slideDown("slow");
                });
        });
    </script>
  </head>
  <body>
    <body>
        <p>Hello java2s.com</p>
    </body>
</html>

Click to view the demo

The code above generates the following result.

.slideDown()

Slide down form fields


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!-- w ww.ja  va2 s .  c  o  m-->
               $("div").click(function () {
                  $("input").slideDown(1000,function(){
                     $(this).focus();
                  });
               });
        });
    </script>
    <style>
      input { display:none;margin:10px; }
    </style>
  </head>
  <body>
    <body>
          <div>Click me java2s.com</div>
          <input type="text" />
          <input type="text"/>
          <input type="text" />
    </body>
</html>

Click to view the demo

The code above generates the following result.

.slideDown()

Slide down in milliseconds


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!--   w ww  .j ava2  s  .co  m-->
                $("p").click(function () {
                    $("p").hide();
                    $("p").slideDown(10000);
                });
        });
    </script>
  </head>
  <body>
    <body>
        <p>Hello java2s.com</p>
    </body>
</html>

Click to view the demo

The code above generates the following result.

.slideDown()

Slide to show paragraph


<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 ava 2s  .  c  o  m-->
           $("div").one('click', function () {
              if ($(this).is(":first-child")) {
                $("p").text("It's the first div.");
              }else{
                $("p").text("It's NOT the first div.");
              }
              $("p").hide().slideDown("slow");
              
           });
        });
    </script>
     <style>
     div { border:2px white solid;}
  </style>

  </head>
  <body>
    <body>
      Press each to see the text.
      <div>java2s.com</div>
      <div>java2s.com</div>
      <div>java2s.com</div>
      <div>java2s.com</div>
      <div>java2s.com</div>
      <div>java2s.com</div>
      <p></p>
  </body>
</html>

Click to view the demo

The code above generates the following result.

.slideDown()

Animate height

Only the height is adjusted for this 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  . j a  v  a2  s  .c  om-->

            $(document.body).click(function () {
              if ($("div:first").is(":hidden")) {
                $("div").slideDown("slow");
              } else {
                $("div").hide();
              }
            });


        });
    </script>

  </head>
  <body>
    <body>
          <div>java2s.com</div><div>java2s.com</div><div>java2s.com</div><div>java2s.com</div>
    </body>
</html>

Click to view the demo

The code above generates the following result.

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