.slideDown()

Syntax

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

Parameters

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

Description

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.

Examples

 
<html>
  <head>
    <script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
           $("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>asdf</div>
      <div>asdf</div>
      <div>asdf</div>
      <div>asdf</div>
      <div>asdf</div>
      <div>asdf</div>
      <p></p>
  </body>
</html>
  
Click to view the demo

The following message shows the usage of slideDown and slideUp

 
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
div {
  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/Book/JavaScriptDemo/jQuery/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

Hide and Slide down

 
<html>
  <head>
    <script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
                $("p").click(function () {
                    $("p").hide();

                    $("p").slideDown();
                });
        });
    </script>
  </head>
  <body>
    <body>
        <p>Hello</p>
    </body>
</html>
  
Click to view the demo

Slide down and set focus

 
<html>
  <head>
    <script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
               $("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

Slide down fast

 
<html>
  <head>
    <script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
                $("p").click(function () {
                    $("p").hide();
                    $("p").slideDown("fast");
                });
        });
    </script>
  </head>
  <body>
    <body>
        <p>Hello</p>
    </body>
</html>
  
Click to view the demo

Slide down slowly

 
<html>
  <head>
    <script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
                $("p").click(function () {
                    $("p").hide();
                    $("p").slideDown("slow");
                });
        });
    </script>
  </head>
  <body>
    <body>
        <p>Hello</p>
    </body>
</html>
  
Click to view the demo

Slide down form fields

 
<html>
  <head>
    <script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
               $("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

Slide down in milliseconds

 
<html>
  <head>
    <script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
                $("p").click(function () {
                    $("p").hide();
                    $("p").slideDown(10000);
                });
        });
    </script>
  </head>
  <body>
    <body>
        <p>Hello</p>
    </body>
</html>
  
Click to view the demo

Slide to show para

 
<html>
  <head>
    <script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
           $("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>asdf</div>
      <div>asdf</div>
      <div>asdf</div>
      <div>asdf</div>
      <div>asdf</div>
      <div>asdf</div>
      <p></p>
  </body>
</html>
  
Click to view the demo

Only the height is adjusted for this animation

 
<html>
  <head>
    <script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){

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


        });
    </script>

  </head>
  <body>
    <body>
          <div>asdf</div><div>asdf</div><div>asdf</div><div>asdf</div>
    </body>
</html>
  
Click to view the demo
Home 
  JavaScript Book 
    jQuery  

Effect:
  1. jQuery Effect
  2. .animate()
  3. .css() does animation
  4. .clearQueue()
  5. .delay()
  6. .dequeue()
  7. $.extend()
  8. .fadeIn()
  9. .fadeOut()
  10. .fadeTo()
  11. .hide()
  12. .queue()
  13. .show()
  14. .slideDown()
  15. slideToggle
  16. .slideUp()
  17. .stop()
  18. .toggle()