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

Toggling the slide [ 83 ] Chapter 4 The final slide method is slideToggle(), which provides rudimentary state-checking in order to determine whether the element should be hidden with slideUp() or shown with slideDown(), and then applies the relevant effect. Like the toggle() method that we looked at earlier, the built-in state checking mechanism is provided as a simple convenience, but there may be situations where we need to provide our own logic. The slideToggle() method may accept the same arguments as the other slide methods, or an object that makes use of easing. For reference, the usage pattern is as follows: jQuery(elements).slideToggle([duration], [easing], [callback]); Time for action – using slideToggle On the checkout pages of e-commerce sites, it's customary to show the products that are in the visitor's basket so that they know exactly what they're buying. Typically the checkout page (or pages) will be quite long due to the amount of information the visitor will need to enter, especially if it is their first visit to the site. The page can often end up requesting names, e-mail addresses, and other contact information, payment methods, and more. Hence, it can be useful to hide the contents of the basket and just show a summary, but to allow the basket to be expanded to show the full details of their purchase. The following screenshot shows how the basket will appear once it has been opened:

Sliding Animations Once the basket area has been expanded, the contents are displayed in full. 1. Let's make a start by creating the underlying HTML. Add the following code to the template file: Basket Summary Show basket contents QtyDescriptionPriceTotal 2£10£20 1£5£5 3£7£21 5 Day standard shipping£10 VAT£10 6 Items£66 2. Save this page as slideToggle.html. 3. Now let's add some basic styling to tidy up and improve the appearance of our example page. In a new file in your text editor, add the following code: #basket { width:860px; margin:auto; position:relative; border:1px solid #000; -moz-border-radius:7px; -webkit-border-radius:7px; border-radius:7px; background-color:#000; font:normal 14px "Nimbus Sans L", "Helvetica Neue", "Franklin Gothic Medium", Sans-serif; [ 84 ]

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

Once the basket area has been expanded, the contents are displayed in full.<br />

1. Let's make a start by creating the underlying HTML. Add the following code to the<br />

template file:<br />

<br />

Basket Summary<br />

Show basket contents<br />

<br />

<br />

QtyDescriptionPriceTotal<br />

2£10£20<br />

1£5£5<br />

3£7£21<br />

5 Day<br />

standard shipping£10<br />

VAT£10<br />

<br />

<br />

<br />

6 Items£66<br />

<br />

<br />

2. Save this page as slideToggle.html.<br />

3. Now let's add some basic styling to tidy up and improve the appearance <strong>of</strong> our<br />

example page. In a new file in your text editor, add the following code:<br />

#basket {<br />

width:860px; margin:auto; position:relative;<br />

border:1px solid #000; -moz-border-radius:7px;<br />

-webkit-border-radius:7px; border-radius:7px;<br />

background-color:#000;<br />

font:normal 14px "Nimbus Sans L", "Helvetica Neue", "Franklin<br />

Gothic Medium", Sans-serif;<br />

[ 84 ]

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

Saved successfully!

Ooh no, something went wrong!