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 ]

Toggling the slide<br />

[ 83 ]<br />

Chapter 4<br />

The final slide method is slideToggle(), which provides rudimentary state-checking in<br />

order to determine whether the element should be hidden with slideUp() or shown with<br />

slideDown(), and then applies the relevant effect. Like the toggle() method that we<br />

looked at earlier, the built-in state checking mechanism is provided as a simple convenience,<br />

but there may be situations where we need to provide our own logic.<br />

The slideToggle() method may accept the same arguments as the other slide methods,<br />

or an object that makes use <strong>of</strong> easing. For reference, the usage pattern is as follows:<br />

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

Time for action – using slideToggle<br />

On the checkout pages <strong>of</strong> e-commerce sites, it's customary to show the products that are<br />

in the visitor's basket so that they know exactly what they're buying. Typically the checkout<br />

page (or pages) will be quite long due to the amount <strong>of</strong> information the visitor will need to<br />

enter, especially if it is their first visit to the site.<br />

The page can <strong>of</strong>ten end up requesting names, e-mail addresses, and other contact<br />

information, payment methods, and more. Hence, it can be useful to hide the contents<br />

<strong>of</strong> the basket and just show a summary, but to allow the basket to be expanded to show<br />

the full details <strong>of</strong> their purchase.<br />

The following screenshot shows how the basket will appear once it has been opened:

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

Saved successfully!

Ooh no, something went wrong!