.hide()
S2C Home « Effects « .hide()
Hiding elements.
Description
The .hide()
method is used to hide the matched set.
- The
display
property of the element to be hidden is stored in the jQuery cache, so if the element is later made visible, thedisplay
property is restored to its initial value. - When any parameters are used, the
.hide()
method becomes an animation method:- The
.hide()
method animates the height, width and opacity of the matched elements simultaneously. - When these properties reach 0, the
display
property is set tonone
ensuring that the page layout is no longer affected by the element.
- The
Syntax
Signature | Description |
---|---|
.hide( ) | Hide the matched set. |
.hide( duration [, callback] ) | Hide the matched set providing a duration and optionally a callback function. |
.hide( [duration] [, easing] [, callback] ) | Hide the matched set optionally providing a duration, and/or an easing and/or a callback function. |
Parameters
Parameter | Description | Type |
---|---|---|
duration | A string or number determining the time the animation will run for. default: 400
| String orNumber |
easing | Specify the speed at which the animation progresses at different points within the animation. default: swing
| String |
callback | A function that fires once the animation is complete.
|
Function |
Return
A jQuery
object.
.hide()
ExampleTop
Hide the matched set.
- When used in its basic form with no parameters the
.hide()
method hides the element immediately with no animation.
In the example below when the button is pressed we hide the image below of thai green curry.
$(function(){
$('#btn1').on('click', function() {
$('#curry1').hide();
});
});
.hide( duration [, callback] )
ExamplesTop
Hide the matched set providing a duration and optionally a callback function.
In the example below when the left button is pressed we hide the image below on the left of chicken masala using a slow 'duration'.
When the right button is pressed we first select all the images of chicken korma (class of 'curry3'). 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.
$(function(){
$('#btn2').on('click', function() {
$('#curry2').hide('slow');
});
$('#btn3').on('click', function() {
$('#div4 .curry3').first().hide(400, function() {
// using 'callee' so we don't have to name the function
$(this).next().hide(400, arguments.callee);
});
});
});
.hide( [duration] [, easing] [, callback]
ExamplesTop
Hide 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 hide 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.
$(function(){
$('#btn4').on('click', function() {
$('#pie1').hide('swing');
});
$('#btn5').on('click', function() {
$('#pie2').hide(function() {
alert('Animation finished.');
});
});
$('#btn6').on('click', function() {
$('#pie3').hide('slow', 'swing', function() {
alert('Animation complete.');
});
});
});
Related Tutorials
jQuery Intermediate Tutorials - Lesson 6 - Basic & Custom Effects