02.06.2013 Views

DOM Traversal Methods

DOM Traversal Methods

DOM Traversal Methods

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Effect <strong>Methods</strong><br />

Parameters<br />

• speed (optional): A string or number determining how long the animation<br />

will run<br />

•<br />

callback (optional): A function to call once the animation is complete<br />

Return Value<br />

The jQuery object, for chaining purposes.<br />

Description<br />

The .slideToggle() method animates the height of the matched elements. This<br />

causes lower parts of the page to slide up or down, appearing to conceal or reveal<br />

the items.<br />

Speeds are given in millisecond durations of the animation; higher values indicate<br />

slower animations, not faster ones. The strings fast, normal, and slow can be<br />

supplied to indicate speed values of 200, 400, and 600 respectively. If the speed<br />

parameter is omitted, normal is assumed.<br />

If supplied, the callback is fired once the animation is complete. This can be useful<br />

for stringing different animations together in sequence. The callback is not sent any<br />

arguments, but this is set to the <strong>DOM</strong> element being animated. The callback is<br />

executed once per matched element, not once for the animation as a whole.<br />

We can animate any element, such as a simple containing an image:<br />

<br />

Trigger<br />

<br />

<br />

<br />

With the element initially displayed, we can hide and show it slowly:<br />

$('.trigger').click(function() {<br />

$('.target').slideToggle('slow', function() {<br />

$(this).log('Effect complete.');<br />

});<br />

});<br />

[ 140 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!