jQuery 1.4 Animation Techniques - Index of
jQuery 1.4 Animation Techniques - Index of jQuery 1.4 Animation Techniques - Index of
[ 185 ] Chapter 7 Within the while loop, we use jQuery's scrollTop() method in setter mode to set the scroll to the value of the newScroll variable, and then increment the newScroll value using our speed variable. This is what I meant by spoofing the animated scroll—the document just scrolls sequentially in a series of jumps; it isn't actually animated, but because it happens fairly rapidly it gives the impression of being animated. After the click handler for the table of contents links, we also set a click handler on the back to top links. Because we're just going straight back to the top of the page, we don't need to do any complex calculations, so this function is really just a simplified version of the first function. There is already a jQuery plugin that can be used to animate scroll: the scrollTo plugin. This plugin allows us to easily animate both vertical and horizontal scroll on any element whose contents overflows the dimensions set on it. However, as an exercise in how to fake animation without using any of jQuery's animation methods, I thought it would be of value to do it ourselves manually here. We'll use the plugin later in the chapter. For reference it was created by Ariel Flesler and can be downloaded from http://flesler.blogspot. com/2007/10/jqueryscrollto.html. Pop quiz – animating page scroll 1. In this example we used old-school JavaScript to obtain a reference to the DOM node instead of using jQuery. Why? a. Because it's easier b. Because it's fun to mix things up a little c. Because it's faster to give jQuery selectors a DOM node context so that the entire document doesn't need to be searched when selecting elements from the page d. Because it makes the byte count of the page smaller 2. Why can we not use jQuery to animate the page scroll? a. Because scrollTop (or window.pageYOffset) are properties of the document or window and not CSS style properties b. Because the values for these properties are not true integers c. Because jQuery does not want us to animate scroll d. We can, we just chose to do it this way instead
Full Page Animations Have a go hero – extending animated page scroll In this example we just animated the vertical scroll of the document. Have a go at changing the example so that the horizontal scroll can also be animated. This will entail making the page not just longer than the viewport, but also wider too. The illusion of depth with parallax The term parallax, when used in the context of computer graphics, especially in video games, refers to the technique of using multiple background layers that scroll at slightly different speeds to create the illusion of depth. Although not as widely deployed in modern gaming, thanks to the advent of richer 3D graphics engines, parallax is still seen frequently in portable gaming devices, and increasingly, on the Web. A parallax effect is achievable using pure CSS, as demonstrated nicely by the Silverback site (see http://silverbackapp.com/ for the effect, and http://thinkvitamin.com/ design/how-to-recreate-silverbacks-parallax-effect/ for the details on how it was implemented). This application of parallax will only become apparent when the window is resized, which is a fantastic effect when the window is resized, but doesn't help us if we want the effect to take more of a center stage. A little help from the new cssHooks functionality jQuery 1.4.3 introduced a new mechanism for easily extending the css() and animate() methods of jQuery. The new cssHooks feature allows us to easily extend the css() method to allow the getting and setting of CSS style properties not natively supported by jQuery. As the animate() method makes use of the css() method internally, we can use the cssHooks to add animation support for certain style properties that previously were unsupported. This is great, but even better is the fact that some of the jQuery core contributors, most notably Mr Brandon Aaron, have already begun building a suite of pre-built cssHooks for certain style properties, including background-position. We can use one of these brand new, pre-built cssHooks in our next example. The file containing the cssHook for background-position is included in the code download accompanying this book, but for reference, the complete suite can be found at https://github.com/brandonaaron/jquery-cssHooks. [ 186 ]
- 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 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: Download from Wow! eBook Full Page
- 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
- Page 221 and 222: Full Page Animations Pop quiz - cre
- Page 223 and 224: Full Page Animations Time for actio
- Page 225 and 226: Full Page Animations Next we define
- Page 228 and 229: 8 Other Popular Animations This cha
- Page 230 and 231: [ 209 ] Chapter 8 } .slider #scroll
- Page 232 and 233: }), pointerText = "Use your pointer
- Page 234 and 235: [ 213 ] Chapter 8 In the previous s
- Page 236 and 237: prox.mousemove(function(ev) { goAni
- Page 238 and 239: Pop quiz - implementing proximity a
- Page 240 and 241: [ 219 ] Chapter 8 What just happene
- Page 242 and 243: 2. Save the new page as marquee.htm
- Page 244 and 245: [ 223 ] Chapter 8 1. jQuery provide
- Page 246 and 247: clear:both; } div#fadeLeft, div#fad
- Page 248 and 249: Time for action - animating the pos
- Page 250: 2. In this example we used the dele
- Page 253 and 254: CSS3 Animations The following trans
- Page 255 and 256: CSS3 Animations Units It is of crit
Full Page <strong>Animation</strong>s<br />
Have a go hero – extending animated page scroll<br />
In this example we just animated the vertical scroll <strong>of</strong> the document. Have a go at changing<br />
the example so that the horizontal scroll can also be animated. This will entail making the<br />
page not just longer than the viewport, but also wider too.<br />
The illusion <strong>of</strong> depth with parallax<br />
The term parallax, when used in the context <strong>of</strong> computer graphics, especially in video games,<br />
refers to the technique <strong>of</strong> using multiple background layers that scroll at slightly different<br />
speeds to create the illusion <strong>of</strong> depth. Although not as widely deployed in modern gaming,<br />
thanks to the advent <strong>of</strong> richer 3D graphics engines, parallax is still seen frequently in portable<br />
gaming devices, and increasingly, on the Web.<br />
A parallax effect is achievable using pure CSS, as demonstrated nicely by the Silverback site<br />
(see http://silverbackapp.com/ for the effect, and http://thinkvitamin.com/<br />
design/how-to-recreate-silverbacks-parallax-effect/ for the details on how it<br />
was implemented). This application <strong>of</strong> parallax will only become apparent when the window<br />
is resized, which is a fantastic effect when the window is resized, but doesn't help us if we<br />
want the effect to take more <strong>of</strong> a center stage.<br />
A little help from the new cssHooks functionality<br />
<strong>jQuery</strong> <strong>1.4</strong>.3 introduced a new mechanism for easily extending the css() and animate()<br />
methods <strong>of</strong> <strong>jQuery</strong>. The new cssHooks feature allows us to easily extend the css()<br />
method to allow the getting and setting <strong>of</strong> CSS style properties not natively supported by<br />
<strong>jQuery</strong>. As the animate() method makes use <strong>of</strong> the css() method internally, we can use<br />
the cssHooks to add animation support for certain style properties that previously were<br />
unsupported.<br />
This is great, but even better is the fact that some <strong>of</strong> the <strong>jQuery</strong> core contributors, most<br />
notably Mr Brandon Aaron, have already begun building a suite <strong>of</strong> pre-built cssHooks for<br />
certain style properties, including background-position. We can use one <strong>of</strong> these brand<br />
new, pre-built cssHooks in our next example.<br />
The file containing the cssHook for background-position is included in the code<br />
download accompanying this book, but for reference, the complete suite can be<br />
found at https://github.com/brandonaaron/jquery-cssHooks.<br />
[ 186 ]