jQuery 1.4 Animation Techniques - Index of
jQuery 1.4 Animation Techniques - Index of jQuery 1.4 Animation Techniques - Index of
[ 141 ] Chapter 6 Optionally, a callback function may be provided as the final argument. The supplied function will be executed once for each selected element when the effect ends. Let's look at a few examples of how the effect() method can be used. The bounce effect The bounce effect is similar to, but much more controllable than, the easeOutBounce easing function. It can be used with either the effect API or show/hide logic depending on your requirements. Configuration options The following configuration options are available for the bounce effect: Option Default Usage direction "up" The direction of bounce. The other possible option is the string down. distance 20 The initial distance of bounce (successive bounces reduce in distance) in pixels. mode "effect" Whether to run the effect normally or use show/hide logic. Other values accepted may be the strings show, hide, or toggle. times 5 The number of bounces. Time for action – using the bounce effect In this example we'll see how the jQuery UI effect can be combined to create a bouncing ball that travels across the page: 1. Use the following simple elements in the of the template file: 2. All we need is a simple container and an inner . In the empty function at the end of the , add the following script: $("#ball").click(function() { $("#travel").animate({ left: "+=300px" }, 2000).find("div").effect("bounce"); });
Extended Animations with jQuery UI 3. Save the file as bounce.html. We also need a few simple styles. Add the following CSS to a new file: #travel { position:absolute; top:100px; } #ball { width:150px; height:150px; cursor:pointer; background:url(../img/ball.jpg) no-repeat 0 0; } 4. Save this as bounce.css in the css folder. When we run the page and click on the ball we should find that it bounces along the page, gradually coming to a halt: The previous composition shows the ball traveling across the page, bouncing up and down as it goes from left to right. What just happened? When the ball is clicked, we first use jQuery's animate() method to animate the left style property of the container by 300 pixels, over a duration of 2 seconds. We slow this animation down to improve the appearance of the overall animation, but it is not strictly required. We then navigate down to the inner element and use the effect() method, specifying the bounce effect. We need to use both elements because if we use the animate() and effect() methods on the same element, the bounce effect will go into the element's animation queue and the two animations will execute one after the other instead of running simultaneously. [ 142 ]
- 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
- Page 154 and 155: [ 133 ] Chapter 5 In the previous s
- Page 156: Have a go hero - extending the plug
- Page 159 and 160: Extended Animations with jQuery UI
- Page 161: Extended Animations with jQuery UI
- Page 165 and 166: Extended Animations with jQuery UI
- Page 167 and 168: Extended Animations with jQuery UI
- Page 169 and 170: Extended Animations with jQuery UI
- Page 171 and 172: Download from Wow! eBook Extended
- Page 173 and 174: Extended Animations with jQuery UI
- Page 175 and 176: Extended Animations with jQuery UI
- Page 177 and 178: Extended Animations with jQuery UI
- Page 179 and 180: Extended Animations with jQuery UI
- Page 181 and 182: Extended Animations with jQuery UI
- Page 183 and 184: Extended Animations with jQuery UI
- Page 185 and 186: Extended Animations with jQuery UI
- Page 187 and 188: Extended Animations with jQuery UI
- Page 189 and 190: Extended Animations with jQuery UI
- Page 191 and 192: Extended Animations with jQuery UI
- Page 193 and 194: Extended Animations with jQuery UI
- Page 195 and 196: Extended Animations with jQuery UI
- Page 197 and 198: Extended Animations with jQuery UI
- Page 199 and 200: Extended Animations with jQuery UI
- Page 201 and 202: Full Page Animations Can we animate
- Page 203 and 204: Full Page Animations display:block;
- Page 205 and 206: Download from Wow! eBook Full Page
- Page 207 and 208: Full Page Animations Have a go hero
- Page 209 and 210: Full Page Animations 4. Save this f
- Page 211 and 212: Full Page Animations 2. The bgpos c
Extended <strong>Animation</strong>s with <strong>jQuery</strong> UI<br />
3. Save the file as bounce.html. We also need a few simple styles. Add the following<br />
CSS to a new file:<br />
#travel { position:absolute; top:100px; }<br />
#ball {<br />
width:150px; height:150px; cursor:pointer;<br />
background:url(../img/ball.jpg) no-repeat 0 0;<br />
}<br />
4. Save this as bounce.css in the css folder. When we run the page and click on the<br />
ball we should find that it bounces along the page, gradually coming to a halt:<br />
The previous composition shows the ball traveling across the page, bouncing up and down as<br />
it goes from left to right.<br />
What just happened?<br />
When the ball is clicked, we first use <strong>jQuery</strong>'s animate() method to animate the left style<br />
property <strong>of</strong> the container by 300 pixels, over a duration <strong>of</strong> 2 seconds. We slow this animation<br />
down to improve the appearance <strong>of</strong> the overall animation, but it is not strictly required. We<br />
then navigate down to the inner element and use the effect() method, specifying<br />
the bounce effect.<br />
We need to use both elements because if we use the animate() and effect() methods<br />
on the same element, the bounce effect will go into the element's animation queue and the<br />
two animations will execute one after the other instead <strong>of</strong> running simultaneously.<br />
[ 142 ]