jQuery API

.slideDown()

.slideDown( [duration] [, callback] ) Returns: jQuery

Description: Display the matched elements with a sliding motion.

  • version added: 1.0.slideDown( [duration] [, callback] )

    durationA string or number determining how long the animation will run.

    callbackA function to call once the animation is complete.

  • version added: 1.4.3.slideDown( [duration] [, easing] [, callback] )

    durationA string or number determining how long the animation will run.

    easingA string indicating which easing function to use for the transition.

    callbackA function to call once the animation is complete.

The .slideDown() method animates the height of the matched elements. This causes lower parts of the page to slide down, making way for the revealed items.

Durations are given in milliseconds; higher values indicate slower animations, not faster ones. The strings 'fast' and 'slow' can be supplied to indicate durations of 200 and 600 milliseconds, respectively. If any other string is supplied, or if the duration parameter is omitted, the default duration of 400 milliseconds is used.

We can animate any element, such as a simple image:

<div id="clickme">
  Click here
</div>
<img id="book" src="book.png" alt="" width="100" height="123" />

With the element initially hidden, we can show it slowly:

$('#clickme').click(function() {
  $('#book').slideDown('slow', function() {
    // Animation complete.
  });
});

Easing

As of jQuery 1.4.3, an optional string naming an easing function may be used. Easing functions specify the speed at which the animation progresses at different points within the animation. The only easing implementations in the jQuery library are the default, called swing, and one that progresses at a constant pace, called linear. More easing functions are available with the use of plug-ins, most notably the jQuery UI suite.

Callback Function

If supplied, the callback is fired once the animation is complete. This can be useful for stringing different animations together in sequence. The callback is not sent any arguments, but this is set to the DOM element being animated. If multiple elements are animated, it is important to note that the callback is executed once per matched element, not once for the animation as a whole.

As of jQuery 1.6, the .promise() method can be used in conjunction with the deferred.done() method to execute a single callback for the animation as a whole when all matching elements have completed their animations ( See the example for .promise() ).

Additional Notes:

  • All jQuery effects, including .slideDown(), can be turned off globally by setting jQuery.fx.off = true, which effectively sets the duration to 0. For more information, see jQuery.fx.off.

Examples:

Example: Animates all divs to slide down and show themselves over 600 milliseconds.

<!DOCTYPE html>
<html>
<head>
  <style>
div { background:#de9a44; margin:3px; width:80px; 
height:40px; display:none; float:left; }
</style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  Click me!
<div></div>
<div></div>
<div></div>
<script>
$(document.body).click(function () {
if ($("div:first").is(":hidden")) {
$("div").slideDown("slow");
} else {
$("div").hide();
}
});

</script>

</body>
</html>

Demo:

Example: Animates all inputs to slide down, completing the animation within 1000 milliseconds. Once the animation is done, the input look is changed especially if it is the middle input which gets the focus.

<!DOCTYPE html>
<html>
<head>
  <style>
div { background:#cfd; margin:3px; width:50px; 
text-align:center; float:left; cursor:pointer;
border:2px outset black; font-weight:bolder; }
input { display:none; width:120px; float:left; 
margin:10px; }
</style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  <div>Push!</div>
<input type="text" />
<input type="text" class="middle" />

<input type="text" />
<script>
$("div").click(function () {
$(this).css({ borderStyle:"inset", cursor:"wait" });
$("input").slideDown(1000,function(){
$(this).css("border", "2px red inset")
.filter(".middle")
 .css("background", "yellow")
 .focus();
$("div").css("visibility", "hidden");
});
});

</script>

</body>
</html>

Demo:

Support and Contributions

Need help with .slideDown() or have a question about it? Visit the jQuery Forum or the #jquery channel on irc.freenode.net.

Think you've discovered a jQuery bug related to .slideDown()? Report it to the jQuery core team.

Found a problem with this documentation? Report it on the GitHub issue tracker

  • http://twitter.com/ChrisMBarr Chris Barr

    If you want to use this effect with an easing transition, just add that string as the 2nd parameter instead of a callback.
    $(“#item”).slideDown(500,”easeOutExpo”);

    But if you want to add easing AND a callback, the syntax changes completely. You must pass in a single object with 3 parameters as follows:

    $(“#item”).slideDown({
    duration:500,
    easing:”easeOutExpo”,
    complete:function(){
    alert(“complete!”);
    }
    });

  • http://ciantic.blogspot.com/ Ciantic

    There is bug in this, it appears to calculate height incorrectly on some situations where height is not known, causing the animation being jumpy.

    Here is fix: http://blog.pengoworks.com/index.cfm/2009/4/21/Fixing-jQuerys-slideDown-effect-ie-Jumpy-Animation

  • http://nihei.dk Nihei

    If you try to apply this effect to an element that has a min-height then the effect doesn’t slide, but instead just shows the element much like .show() does.

  • Honglele22

    slideDown effect is so slow when content is so large
    Please take a look to this link
    http://fitness.isport.com/fitness-gyms/?l=Burli…
    and click on “Narrow Your Choices:”, slide is so slow on IE and FF
    Do you have any good solution for this
    Thanks

  • Liuhui

    不错

  • http://rockingteam.com Alex Jose

    What do we use to inject an element with a sliding motion? Like in http://google.com/realtime . You have noticed the difference in normal slideDown and the realtime sliding motion. How can we implement that?

  • http://www.baby-pictures.org zsameer

    thanks for great tutorial.

  • http://www.baby-pictures.org zsameer

    thanks for great tutorial.

  • http://www.baby-pictures.org zsameer

    thanks for great tutorial.

  • http://www.baby-pictures.org zsameer

    thanks for great tutorial.

  • MakMansoor

    its nice, but can anyone tel me , how to scrolling the data in sharepoint Rssviewer webpart

    using jquery.

  • Simonholt26

    Is it possible to include a delay after mouse 'hovers out' before the slides up again?

  • http://twitter.com/robcolburn Rob Colburn

    I often find myself coding something like
    $("a.expandthis").click(function() {
    $(this).slideUp().next().slideDown();
    return false;
    });

    On content-heavy page, jQuery will stall to do the animation, or sometimes skip it entirely.

    That's pretty annoying, and I needed a solution, so I do this a lot now

    $("a.expandthis").click(function() {
    window.setTimeout(function(){
    $(this).slideUp().next().slideDown();
    return false;
    },1);
    });

    This seems to do the trick, jQuery now has all the time it needs to get things done since it's no longer firing from a click event.

  • dax32

    I cannot find the strings for easing!
    what are they?

  • ted

    Can it work with .load() ? I can not do any animations on any my ajax requests, like:

    $('#result').load('../page.php').slideDown('slow');

  • chrissp26

    The first example doesn't work in IE8 (the Click Me one). Works fine in IE7, FF, Chrome, Safari etc.

    • Diane Ramsey

      I have mine working in IE8.

  • http://twitter.com/NakedxBabe Perfection Queenie

    How can i put this on a page with other divs so it doesn't interfere and put those inside as well?
    i put it on my page i already made with a few divs and it brought them inside too even when i used div id “a” and “b” then “c” .e.t.c but it didn't work in getting them not to interfere.

  • Nsimic

    it does not work properly if the target is a table.
    solution would be to wrap a table in a div

    • Alex

      I would add that it doesn't work properly if target is . The solution is the same.

      • Alex

        … if target is td

  • Dongarcia

    I love the slide-show – but is there a way to stop the rolling text with the background and instead show the text with the background when the image appears?

  • M.Pugh

    I have been having an issue with the animation of a UL inside of an LI. You can see at the link below, the links with title attributes pertaining to comments.

    http://jsfiddle.net/uFWWf/

  • Tony Lea

    I love the jQuery slideUp and slideDown functionality. Such simple functionality with a simple call . Please feel free to check out my beginner tutorial at: http://www.tonylea.com/2010/jq…/

    Thanks

  • jq

    This is very nice function in jQuery. You should hurry up to to try it and apply it on your own website or projects!

  • snake_programmer

    thanks! very useful.

  • Alex

    I would add that it doesn't work properly if target is . The solution is the same.

  • Alex

    … if target is td

  • Ramico

    this make the element display block i want it to be table

  • bsutcliffe

    Beyond Coding have come up with a fix – http://j.mp/aH6wYe (cf Issue 1). Not sure how great that fix actually will be, not entirely convinced that making the holder div positioned relative will actually work. I'm using fadeIn and show till I can confidently use slideDown.