Saturday 16 May 2015

JQuery Tutorial : Part 4 : Slide Effect

Fade Effect : JQuery

In this part of tutorial we will learn about the slide effect in JQuery. JQuery slides method used to slide up and down the content of a web page. It have three methods which are as follows :

  • jQuery slideDown()
         Demonstrates the jQuery slideDown() method.
  • jQuery slideUp()
         Demonstrates the jQuery slideUp() method.
  • jQuery slideToggle()
         Demonstrates the jQuery SlideToggle() method.

Basic syntax :

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

Here speed is optional, it defines the speed of slide up and down of the element on which it has been applied. It can takes parameter "slow","fast",milliseconds.

Example :

 


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<html>
 <head>
 <title>jquery example</title>
 <!-- This line will load the bootstrap css file  -->
 <link rel="stylesheet" type="text/css" href="bootstrap.min.css">
 <!-- This file will load jquery file so that we can use its function -->
 <script type="text/javascript" src="jquery-1.7.2.min.js"></script>
 </head>
 <body>
 <div class="panel panel-primary">
  <h3 class="text-primary" align="center"> jquery example : slideDown() method</h3>
  
 </div>
 <div id="div1" class="panel panel-primary" style="background-color:yellow;">
  <p  align="center" class="text text-primary">Click on this panel to slide down another panel below this. This is the div with id="div1"</p>
 </div>
 <div id="div2" align="center" style="background-color:yellow;display:none;" class="panel panel-primary">
  <p align="center" style="background-color:yellow;" class="text text-primary">This is the under the div with id="div2"</p>
 </div>
 </body>
 <script type="text/javascript">
 $(document).ready(function(){
    $("#div1").click(function(){ 
     /*On the click of div with id="div1" the dive with id="div2" will slide down slowly
     syntax : $(selector).slideDown(speed,callback);*/
     $("#div2").slideDown("slow");
    });
 });
 </script>
</html>

In the above example, on the click of div with id="div1", the div with id="div2" will slide down. Similarly you can have your slideUp() method which will slide the <div> up and the slideToggle() method which will slide the <div> up if it is down and vice-versa.

The working example can be downloaded from git also.

0 comments:

Post a Comment

 

Copyright @ 2013 Appychip.

Designed by Appychip & YouTube Channel