jQuery 1.4 Animation Techniques - Index of

jQuery 1.4 Animation Techniques - Index of jQuery 1.4 Animation Techniques - Index of

02.06.2013 Views

Pop quiz – sliding elements down 1. What should be applied to an element before it has the slideDown() method called on it? a. visibility:hidden; b. height:0; c. display:none; d. position:static; [ 79 ] Chapter 4 2. What style does an element that has been shown with slideDown() end up with? a. display:block; b. visibility:visible; c. position:absolute; d. height:100%; Have a go hero – sliding elements down In our basic example, once the form has been opened it then stays open until the page is reloaded. Add some additional code that fades the login form away after a specified length of time in case it is not interacted with. Sliding elements out of view The slideUp() method works in exactly the same way as slideDown(), except that it hides the target element instead of showing it. The slideUp() method accepts the same arguments as slideDown() and can be affected by CSS in the same way, so padding and margin should be taken into account and caution is advised when using absolute positioning. The original value of an element's display property however, is not a factor when using slideUp(). The method's pattern of usage is as follows: jQuery(elements).slideUp([duration], [easing], [callback]);

Sliding Animations Time for action – sliding elements up Let's build on the previous example so that the form slides back up out of view if a cancel link is clicked. We can add this link to the underlying markup for the page: 1. In slideDown.html, change the form so that it appears as follows (new code is highlighted): Login Form Username: Password: Remember me: Cancel Login 2. Save the new file as slideUp.html. 3. We'll also need some more styles in order to stop our new link from picking up the styling of the login link. At the end of the slideDown.css stylesheet, add the following new selectors and rules: header ul li a#cancel { margin:0; padding:0; position:absolute; bottom:14px; left:10px; font-size:11px; color:#993333; } header ul li a#cancel:hover, header ul li a#cancel:focus { border:none; text-decoration:underline; color:#ff0000; } 4. Save the updated file in the css folder as slideUp.css, and update the in the of slideUp.html to point to the new stylesheet. 5. To add the new behavior, update the at the bottom of the page so that it includes the following new code: $("#cancel").click(function(e) { e.preventDefault(); $(this).closest("form").slideUp(function() { [ 80 ]

Pop quiz – sliding elements down<br />

1. What should be applied to an element before it has the slideDown() method<br />

called on it?<br />

a. visibility:hidden;<br />

b. height:0;<br />

c. display:none;<br />

d. position:static;<br />

[ 79 ]<br />

Chapter 4<br />

2. What style does an element that has been shown with slideDown() end up with?<br />

a. display:block;<br />

b. visibility:visible;<br />

c. position:absolute;<br />

d. height:100%;<br />

Have a go hero – sliding elements down<br />

In our basic example, once the form has been opened it then stays open until the page is<br />

reloaded. Add some additional code that fades the login form away after a specified length<br />

<strong>of</strong> time in case it is not interacted with.<br />

Sliding elements out <strong>of</strong> view<br />

The slideUp() method works in exactly the same way as slideDown(), except that it<br />

hides the target element instead <strong>of</strong> showing it. The slideUp() method accepts the same<br />

arguments as slideDown() and can be affected by CSS in the same way, so padding<br />

and margin should be taken into account and caution is advised when using absolute<br />

positioning. The original value <strong>of</strong> an element's display property however, is not a factor<br />

when using slideUp().<br />

The method's pattern <strong>of</strong> usage is as follows:<br />

<strong>jQuery</strong>(elements).slideUp([duration], [easing], [callback]);

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

Saved successfully!

Ooh no, something went wrong!