jQuery 1.4 Animation Techniques - Index of
jQuery 1.4 Animation Techniques - Index of jQuery 1.4 Animation Techniques - Index of
[ 149 ] Chapter 6 In the previous screenshot, we see the text fields being shaken when they are left empty and the is clicked. What just happened? When the is clicked we simply check to see if each has a value and if not, we apply a red border and then call the effect() method specifying shake as the effect. We use a configuration object to reduce the distance the element moves, as well as specifying a relatively short duration. The size effect The size effect is used to resize an element, making it grow or shrink depending on its configuration. Unlike most of the other effects, the size effect must be configured for it to be used successfully. The size effect is also one of the only effects that has the base core file as well as another effect as dependencies. Most components rely only on the core file. As we downloaded the entire effect suite from the jQuery UI download builder, we don't need to worry about including the additional effect. It's already in the single file that the download builder created when we downloaded it at the start of the chapter. Configuration options The size effect gives us four configurable options, which are listed as follows: Option Default Usage from none Sets the size of the target element at the beginning of the animation. This option accepts an object with height and width keys which are used to set the starting size of the target element. This option is not mandatory. to none Sets the size of the target element at the end of the animation. This option accepts an object with height and width keys which are used to set the ending size of the target element. This option must be supplied. origin ['middle ', 'center'] Sets the vanishing point for hiding animations, or the point from which it grows when used with show logic. scale "both " This option sets whether the whole box of the element (including border and padding CSS values) is scaled, just the content, or as in the default, both.
Download from Wow! eBook Extended Animations with jQuery UI Time for action – resizing elements A popular use of growing and shrinking elements is the Fisheye menu, where elements grow when the mouse pointer hovers over them, and shrink back down when the pointer moves off them. This effect is also used by the icons on the dock in Apple's OSX. Using the size effect, we can implement our own basic Fisheye menu with just a few lines of code. 1. Add the following markup to the of the template file: 2. Add the following JavaScript to the third element at the bottom of the : $(".icon", "#dock").hover(function() { $(this).stop().animate({ top: -31 }).find("img").stop().effect("size", { to: { width: 64, height: 64 } }); }, function() { $(this).stop().animate({ top: -15 }).find("img").stop().effect("size", { to: { width: 48, height: 48 } }); }); 3. Save this file as size.html. We also need some styling. In a new file add the following code: #dock { width:380px; height:90px; position:fixed; bottom:0; [ 150 ]
- 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 and 162: Extended Animations with jQuery UI
- Page 163 and 164: 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: Extended Animations with jQuery UI
- 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
- Page 213 and 214: Full Page Animations nav ul { margi
- Page 215 and 216: Full Page Animations screensize = {
- Page 217 and 218: Full Page Animations What just happ
- Page 219 and 220: Full Page Animations The second sec
Download from Wow! eBook <br />
Extended <strong>Animation</strong>s with <strong>jQuery</strong> UI<br />
Time for action – resizing elements<br />
A popular use <strong>of</strong> growing and shrinking elements is the Fisheye menu, where elements grow<br />
when the mouse pointer hovers over them, and shrink back down when the pointer moves<br />
<strong>of</strong>f them. This effect is also used by the icons on the dock in Apple's OSX.<br />
Using the size effect, we can implement our own basic Fisheye menu with just a few lines<br />
<strong>of</strong> code.<br />
1. Add the following markup to the <strong>of</strong> the template file:<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
2. Add the following JavaScript to the third element at the bottom <strong>of</strong> the<br />
:<br />
$(".icon", "#dock").hover(function() {<br />
$(this).stop().animate({<br />
top: -31<br />
}).find("img").stop().effect("size", {<br />
to: { width: 64, height: 64 }<br />
});<br />
}, function() {<br />
$(this).stop().animate({<br />
top: -15<br />
}).find("img").stop().effect("size", {<br />
to: { width: 48, height: 48 }<br />
});<br />
});<br />
3. Save this file as size.html. We also need some styling. In a new file add the<br />
following code:<br />
#dock {<br />
width:380px; height:90px; position:fixed; bottom:0;<br />
[ 150 ]