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.

Sliding <strong>Animation</strong>s<br />

Time for action – sliding elements up<br />

Let's build on the previous example so that the form slides back up out <strong>of</strong> view if a cancel<br />

link is clicked. We can add this link to the underlying markup for the page:<br />

1. In slideDown.html, change the form so that it appears as follows<br />

(new code is highlighted):<br />

<br />

Login Form<br />

Username:<br />

Password:<br />

Remember me:<br />

Cancel<br />

Login<br />

<br />

2. Save the new file as slideUp.html.<br />

3. We'll also need some more styles in order to stop our new link from picking up<br />

the styling <strong>of</strong> the login link. At the end <strong>of</strong> the slideDown.css stylesheet, add<br />

the following new selectors and rules:<br />

header ul li a#cancel {<br />

margin:0; padding:0; position:absolute; bottom:14px; left:10px;<br />

font-size:11px; color:#993333;<br />

}<br />

header ul li a#cancel:hover, header ul li a#cancel:focus {<br />

border:none; text-decoration:underline; color:#ff0000;<br />

}<br />

4. Save the updated file in the css folder as slideUp.css, and update the <br />

in the <strong>of</strong> slideUp.html to point to the new stylesheet.<br />

5. To add the new behavior, update the at the bottom <strong>of</strong> the page so that it<br />

includes the following new code:<br />

$("#cancel").click(function(e) {<br />

e.preventDefault();<br />

$(this).closest("form").slideUp(function() {<br />

[ 80 ]

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

Saved successfully!

Ooh no, something went wrong!