jQuery 1.4 Animation Techniques - Index of
jQuery 1.4 Animation Techniques - Index of jQuery 1.4 Animation Techniques - Index of
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 ]
- Page 54 and 55: Download from Wow! eBook The follo
- Page 56 and 57: [ 35 ] Chapter 2 The CSS is used mo
- Page 58 and 59: The fadeTo() method is used in the
- Page 60 and 61: [ 39 ] Chapter 2 #messageList table
- Page 62 and 63: [ 41 ] Chapter 2 What just happened
- Page 64 and 65: 2. What format can these arguments
- Page 66 and 67: } var el = $(this); if (el.css("fil
- Page 68 and 69: [ 47 ] Chapter 2 Usually these meth
- Page 70 and 71: Time for action - animations with s
- Page 72 and 73: Download from Wow! eBook [ 51 ] Ch
- Page 74 and 75: 2. Save the changes as toggle.html.
- Page 76 and 77: 3 Managing Animations Like most of
- Page 78 and 79: [ 57 ] Chapter 3 A custom queue tha
- Page 80 and 81: If we wish to see how many function
- Page 82 and 83: 2. What does the queue() method ret
- Page 84 and 85: [ 63 ] Chapter 3 The argument we su
- Page 86 and 87: [ 65 ] Chapter 3 We pass a callback
- Page 88 and 89: [ 67 ] Chapter 3 The first argument
- Page 90 and 91: Delaying queue execution [ 69 ] Cha
- Page 92 and 93: [ 71 ] Chapter 3 Also note that the
- Page 94 and 95: 4 Sliding Animations Another type o
- Page 96 and 97: Time for action - creating a slide-
- Page 98 and 99: [ 77 ] Chapter 4 header form input
- Page 100 and 101: Pop quiz - sliding elements down 1.
- Page 102 and 103: Download from Wow! eBook }); }); $
- Page 106 and 107: [ 85 ] Chapter 4 } h2 { margin:0; p
- Page 108 and 109: [ 87 ] Chapter 4 The previous scree
- Page 110 and 111: Pop quiz - using slideToggle 1. Wha
- Page 112 and 113: [ 91 ] Chapter 4 Easing is a great
- Page 114 and 115: [ 93 ] Chapter 4 Home Articles J
- Page 116 and 117: [ 95 ] Chapter 4 3. Save this file
- Page 118 and 119: In the previous screenshot, we see
- Page 120 and 121: Pop quiz - fixing the flicker 1. Wh
- Page 122 and 123: 5 Custom Animations The predefined
- Page 124 and 125: An alternative syntax for animate()
- Page 126 and 127: [ 105 ] Chapter 5 width:295px; marg
- Page 128 and 129: [ 107 ] Chapter 5 What just happene
- Page 130 and 131: [ 109 ] Chapter 5 Although not esse
- Page 132 and 133: [ 111 ] Chapter 5 The previous scre
- Page 134 and 135: [ 113 ] Chapter 5 The styles we use
- Page 136 and 137: [ 115 ] Chapter 5 What just happene
- Page 138 and 139: }, html: copy, width: expander.widt
- Page 140 and 141: [ 119 ] Chapter 5 If the image alre
- Page 142 and 143: [ 121 ] Chapter 5 d. Two objects wh
- Page 144 and 145: [ 123 ] Chapter 5 text-align:center
- Page 146 and 147: [ 125 ] Chapter 5 What just happene
- Page 148 and 149: [ 127 ] Chapter 5 Finally, we retur
- Page 150 and 151: [ 129 ] Chapter 5 Once we've define
- Page 152 and 153: } }; $(config.selector).find("a").c
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 ]