jQuery .slideDown() slides down HTML elements

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 w w w  .ja  v a  2s . co  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

slideDown and slideUp

The following message shows the usage of slideDown and slideUp


<!DOCTYPE html>
<html>
<head>
<style type="text/css">
div {<!--   w w  w . j  a  v a2 s .com-->
  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

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(){<!--  w  w w .  j  av  a2 s  . c o m-->
                $("p").click(function () {
                    $("p").hide();

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

Click to view the demo

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  w  w.j a va 2 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</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/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!-- w  w w .ja va 2 s.  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

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(){<!-- w w  w  . ja  v  a2 s .c  o  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

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(){<!--from w w  w .j a v  a2  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 java2s.com</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/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!-- www  .  j  a v a2 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

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(){<!--   w w w. j  a  v  a 2  s  .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

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 va  2  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





















Home »
  jQuery »
    jQuery Tutorial »




Basics
Selector
DOM
Event
Effect
Utilities