.show()S2C Home « Effects « .show()

Showing elements.

Description

The .show() method is used to show the matched set.

  • The display property of the element to be shown is restored to its initial value. If using !important in your styles, it is necessary to override the style using .css('display', 'block !important') for the .show() method to function correctly
  • When any parameters are used, the .show() method becomes an animation method.

Syntax

Signature Description
.show( )Show the matched set.
.show( duration [, callback] )Show the matched set providing a duration and optionally a callback function.
.show( [duration] [, easing] [, callback] )Show the matched set optionally providing a duration, and/or an easing and/or a callback function.

Parameters

Parameter Description Type
durationA string or number determining the time the animation will run for.
default: 400
  • Durations are given in milliseconds and the higher the value, the slower the animation.
  • The string 'slow' can be used which equates to 600 milliseconds.
  • The string 'fast' can be used which equates to 200 milliseconds.
String or
Number
easingSpecify the speed at which the animation progresses at different points within the animation.
default: swing
  • The string 'swing' which is the default and causes the animation to animate faster at the beginnging/end and slower in the middle.
  • The string 'linear' which causes the animation to progress at a constant pace.
String
callbackA function that fires once the animation is complete.
  • The callback is fired in the context of the current element in the set being animated, so the keyword this refers to that element.
  • The callback is fired once for each element in the matched set and can be used to string different animations together in sequence.
Function

Return

A jQuery object.

.show() ExampleTop

Show the matched set.

  • When used in its basic form with no parameters the .show() method shows the element immediately with no animation.

In the example below when the button is pressed we show the image below of thai green curry.

a picture of curry


$(function(){
  $('#btn7').on('click', function() {
    $('#curry4').show();
  });
});

Press the buttons below to action the above code:


.show( duration [, callback] ) ExamplesTop

Show the matched set providing a duration and optionally a callback function.

When we press the left button below is pressed we show the image below on the left of chicken masala using a slow 'duration'.

When we press the right button we first select all the images of chicken korma (class of 'curry6'). After this we use the .first() method to extract the first image in the set and pass this through the callback function. Within the function we use the .next() method to cycle through the images, hiding each in turn with a animation speed of 400 milliseconds.

a picture of curry a picture of curry a picture of curry a picture of curry a picture of curry




$(function(){
  $('#btn8').on('click', function() {
    $('#curry5').show('slow');
  });
  $('#btn9').on('click', function() {
    $('#div2 .curry6').first().show(400, function() {
      // using 'callee' so we don't have to name the function
      $(this).next().show(400, arguments.callee);
    });
  });
});

Press the buttons below to action the above code:

          


.show( [duration] [, easing] [, callback] ) ExamplesTop

Show the matched set optionally providing a duration, and/or an easing and/or a callback function.

In the example below when the left button is pressed we use 'swing' easing to animate the picture as we show it.

When the centre button is pressed we use a callback to alert when the image is hidden.

When the right button is pressed we use a duration, easing and a callback to alert when the image is hidden.

a picture of pie a picture of pie a picture of pie


$(function(){
  $('#btn10').on('click', function() {
    $('#pie4').show('swing');
  });
  $('#btn11').on('click', function() {
    $('#pie5').show(function() {
      alert('Animation finished.');
    });
  });
  $('#btn12').on('click', function() {
    $('#pie6').show('slow', 'swing', function() {
      alert('Animation complete.');
    });
  });
});

Press the buttons below to action the above code: