jQuery Effects - Sliding


jQuery Sliding Methods

With jQuery you can create a smooth effect on objects.

jQuery has the following slide methods:

  • slideDown()
  • slideUp()
  • slideToggle()

jQuery slideDown() Method

The jQuery slideDown() method is used to slide an object.

Syntax:


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

Optional speed parameter specifies the duration of the output. It can take the following values: "slow", "fast", or milliseconds.

Optional callback parameter is a function to be used after you have finished sliding.

The following example illustrates slideDown() method:


Example
$("#flip").click(function(){
  $("#panel").slideDown();
});


jQuery slideUp() Method

The jQuery slideUp() method is used for sliding over an object.

Syntax:


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

Optional speed parameter specifies the duration of the output. It can take the following values: "slow", "fast", or milliseconds.

Optional callback parameter is a function to be used after you have finished sliding.

The following example illustrates slideUp() method:


Example
$("#flip").click(function(){
  $("#panel").slideUp();
});


jQuery slideToggle() Method

The jQuery slideToggle() method switches between slideDown() and slideUp() modes.

If the elements are slipped down, slideToggle() will slide upwards.

If the elements slide up, slideToggle() will slide down.


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

Optional speed parameter can take the following values: "slow", "fast", milliseconds.

Optional callback parameter is a function to be used after you have finished sliding.

The following example illustrates slideToggle() method:


Example
$("#flip").click(function(){
  $("#panel").slideToggle();
});