.slideUp()

Syntax and Description

$(selector).slideUp([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.

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

Slide up fast


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

.slideUp()

Click to slide up


<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  a 2  s  . c  om-->
              $("p").click(function () { 
                   $(this).slideUp(); 
              });
        });
    </script>
  </head>
  <body>
    <body>
       <p>java2s.com</p>
       <p>java2s.com</p>
    </body>
</html>

Click to view the demo

The code above generates the following result.

.slideUp()

Slide up a DIV tag


<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  a  2  s . com-->
               $("div").click(function () {
                    $("div").slideUp();
               });
        });
    </script>
  </head>
  <body>
    <body>
          <div>Click me</div>
    </body>
</html>

Click to view the demo

The code above generates the following result.

.slideUp()

Slide up callback


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!-- ww w  .ja v  a2 s  .c  om-->
               $("button").click(function () {
                  $(this).parent().slideUp("slow", function () {
                      alert("done");
                  });
               });
        });
    </script>
  </head>
  <body>
    <body>
          <div>Click me<button>button</button></div>
    </body>
</html>

Click to view the demo

The code above generates the following result.

.slideUp()

Slide up form controls


<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 . jav a2s . c o m-->
               $("button").click(function () {
                  $(this).parent().slideUp("slow", function () {
                      alert("done");
                  });
               });
        });
    </script>
  </head>
  <body>
    <body>
          <div>Click me<button>button</button></div>
    </body>
</html>

Click to view the demo

The code above generates the following result.

.slideUp()

Slide up in milliseconds


<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.java 2  s  . co  m-->
               $("div").click(function () {
                    $("div").slideUp(2000);
               });
        });
    </script>
  </head>
  <body>
    <body>
          <div>Click me java2s.com</div>
    </body>
</html>

Click to view the demo

The code above generates the following result.

.slideUp()

Slide up slowly


<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 av  a2s .  co  m-->
               $("div").click(function () {
                    $("div").slideUp("slow");
               });
        });
    </script>
  </head>
  <body>
    <body>
          <div>Click me java2s.com</div>
    </body>
</html>

Click to view the demo

The code above generates the following result.

.slideUp()

Animates div to slide up

Animates div to slide up, completing the animation within 400 milliseconds.


<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 av  a2 s . c  om-->
            $(document.body).click(function () {
              if ($("div:first").is(":hidden")) {
                $("div").show("slow");
              } else {
                $("div").slideUp();
              }
            });
        });
    </script>
  </head>
  <body>
    <body>
        Click me!
          <div>java2s.com</div>
          <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.

.slideUp()

Animates all form controls to slide up


<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  2s.  com-->
            $("button").click(function () {
              $(this).parent().slideUp("slow", function () {
                $("#msg").text($("button", this).text() + " has completed.");
              });
            });
        });
    </script>
  </head>
  <body>
    <body>
        <button>Hide One</button>
        <input type="text" value="One" />
        <button>Hide Two</button>
        <input type="text" value="Two" />
        <button>Hide Three</button>
    
        <input type="text" value="Three" />
        <div id="msg"></div>
    </body>
</html>

Click to view the demo

The code above generates the following result.

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