02.06.2013 Views

jQuery 1.4 Animation Techniques - Index of

jQuery 1.4 Animation Techniques - Index of

jQuery 1.4 Animation Techniques - Index of

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.

Extended <strong>Animation</strong>s with <strong>jQuery</strong> UI<br />

The slide effect<br />

The slide effect is very similar to the drop effect. The only difference is that with slide the<br />

opacity <strong>of</strong> the target element is not adjusted at all. It's also very similar to the slide family <strong>of</strong><br />

effects exposed by <strong>jQuery</strong> itself, although with the <strong>jQuery</strong> UI slide effect, we're not restricted<br />

to the vertical axis—we can slide horizontally too.<br />

Configuration options<br />

The slide effect has three configuration options which let us specify the direction and<br />

distance <strong>of</strong> the slide, and whether it is shown or hidden:<br />

Option Default Usage<br />

direction "left" Sets the direction the animation proceeds in.<br />

distance The width <strong>of</strong> the target<br />

element, including padding<br />

Sets the distance that the target element slides to.<br />

mode "show" Sets whether the element is displayed or hidden<br />

when used with the effect() method. Other<br />

acceptable values are hide, effect, and toggle.<br />

Time for action – sliding elements in and out <strong>of</strong> view<br />

Displaying captions when a visitor hovers over an image is an interactive and interesting way<br />

<strong>of</strong> displaying additional information about the image without making your design appear<br />

cluttered. With the slide effect we can easily animate the showing and hiding <strong>of</strong> the caption,<br />

which is what we'll do in this example.<br />

1. Add the following code to <strong>of</strong> the template file:<br />

<br />

<br />

Praying Mantis: Mantis religiosa<br />

<br />

2. Then at the bottom <strong>of</strong> the page, in the empty function, add the following<br />

short script:<br />

$("#image").hover(function() {<br />

$(this).find("div").stop(true, true).show("slide");<br />

}, function() {<br />

$(this).find("div").stop(true, true).hide("slide");<br />

});<br />

[ 168 ]

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

Saved successfully!

Ooh no, something went wrong!