jQuery Effect - Slide

jQuery sliding method

With jQuery, you can create sliding effects on elements.

jQuery has the following sliding methods:

slideDown()

slideUp()

slideToggle()


jQuery slideDown() method

jQuery slideDown() method is used to slide elements down.

Syntax:

$(selector).slideDown(speed,callback);

The optional speed parameter specifies the duration of the effect. It can take the following values: "slow", "fast", or milliseconds.

The optional callback parameter is the name of the function executed after the sliding is completed.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script> 
$(document).ready(function(){
  $("#flip").click(function(){
    $("#panel").slideDown("slow");
  });
});
</script>
 
<style type="text/css"> 
#panel,#flip
{
padding:5px;
text-align:center;
background-color:#e5eecc;
border:solid 1px #c3c3c3;
}
#panel
{
padding:50px;
display:none;
}
</style>
</head>
<body>
 
<div id="flip">点我滑下面板</div>
<div id="panel">Hello world!</div>
</body>
</html>

jQuery slideUp() method

jQuery slideUp() method is used to slide elements up.

Syntax:

$(selector).slideUp(speed,callback);

The optional speed parameter specifies the duration of the effect. It can take the following values: "slow", "fast", or milliseconds.

The optional callback parameter is the name of the function executed after the sliding is completed.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script> 
$(document).ready(function(){
  $("#flip").click(function(){
    $("#panel").slideUp("slow");
  });
});
</script>
 
<style type="text/css"> 
#panel,#flip
{
padding:5px;
text-align:center;
background-color:#e5eecc;
border:solid 1px #c3c3c3;
}
#panel
{
padding:50px;
}
</style>
</head>
<body>
<div id="flip">点我拉起面板</div>
<div id="panel">Hello world!</div>
</body>
</html>

jQuery slideToggle() method

jQuery slideToggle() method can switch between slideDown() and slideUp() methods.

If elements slide down, slideToggle() slides them up.

If elements slide up, slideToggle() slides them down.

$(selector).slideToggle(speed,callback);

The optional speed parameter specifies the duration of the effect. It can take the following values: "slow", "fast", or milliseconds.

The optional callback parameter is the name of the function executed after the sliding is completed.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script> 
$(document).ready(function(){
  $("#flip").click(function(){
    $("#panel").slideToggle("slow");
  });
});
</script>
 
<style type="text/css"> 
#panel,#flip
{
padding:5px;
text-align:center;
background-color:#e5eecc;
border:solid 1px #c3c3c3;
}
#panel
{
padding:50px;
display:none;
}
</style>
</head>
<body>
<div id="flip">显示或隐藏面板。</div>
<div id="panel">Hello world!</div>
</body>
</html>


Continuing Learning
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript"> $().ready(function () { $("#bta").click(function () { $("#unit").stop(true, false).animate({"left": 0}, 500); }); $("#btb").click(function () { $("#unit").stop(true, false).animate({"left": -300}, 500); }) }); </script> <style type="text/css"> * { padding: 0; margin: 0;} #box {width: 300px; height: 150px; margin-bottom: 50px; position: relative; overflow: hidden; } #unit { width: 600px; position: absolute; } #unit div {float: left; width: 300px; height: 150px;} #bga {background-color: #F30;} #bgb {background-color: #F90;} #bta, #btb { float: left; width: 50px; padding-right: 50px; color: #FFF; cursor: pointer;} </style> </head> <body> <div style="width:800px; height:300px; padding-top:100px; background-color:#999; margin:0 auto;"> <div id="box"> <div id="unit"> <div id="bga">框一</div> <div id="bgb">框二</div> </div> </div> <div id="bta">左</div> <div id="btb">右</div> </div> </body> </html>
submitReset Code