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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

What just happened?<br />

We added a new click-handler in much the same way as we did before, including cancelling<br />

the default behavior <strong>of</strong> the browser using the event object (e). In this example, we don't<br />

particularly need to do this because the login form is at the very top <strong>of</strong> the page, so the<br />

visitor won't have scrolled down the page at all and there won't be a jump to the top <strong>of</strong> the<br />

page when either the Login or Cancel links are clicked. However, I have included it here as it<br />

is good practice.<br />

We then find the closest parent <strong>of</strong> the link that is a and call the slideUp() method<br />

on it. This time we also supply a callback function, which is used to remove the on class from<br />

the Login link.<br />

You should notice that the Cancel link does not behave like the other elements in the form<br />

while the form is sliding open or closed. The link is visible all the time and moves with the<br />

bottom <strong>of</strong> the form as it grows or shrinks (depending on whether the form is opening or<br />

closing). The reason for this is simple—it's because the Cancel link is positioned absolutely.<br />

We've specifically added the CSS that causes the Cancel link to behave in this way, even<br />

though it is generally undesirable, as a reminder that CSS can <strong>of</strong>ten cause issues when<br />

combined with animations.<br />

Pop quiz – sliding elements up<br />

1. What is the only requirement for an element to have the slideUp() method called<br />

on it?<br />

a. It should be set to visibility:visible;<br />

b. It should contain a wrapper element<br />

c. It should have a minimum height <strong>of</strong> 100 pixels<br />

d. It should be an element with a display type that naturally renders it visible<br />

on the page<br />

Have a go hero – fixing the Cancel link<br />

Have a go at fixing the Cancel link so that it is only visible while the form is fully open.<br />

The change is simple and requires just a few tweaks to the CSS.<br />

[ 82 ]

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

Saved successfully!

Ooh no, something went wrong!