jQuery 1.4 Animation Techniques - Index of
jQuery 1.4 Animation Techniques - Index of jQuery 1.4 Animation Techniques - Index of
[ 21 ] Chapter 2 We can control the duration of the animation using the duration argument to specify either an integer in milliseconds or one of the strings slow or fast, which are shortcuts for durations of 600 or 200 milliseconds, respectively. We can also supply 0 as the duration argument, which will effectively disable the animation. It's unlikely that we'd need to do this as it would be more efficient to not use an animation at all, but it is useful to know. I should point out that the fade will still occur; it will just happen over a duration of 0 milliseconds. The duration argument relates to the length of time the animation takes to run, not the speed of the animation. Therefore, a higher value will mean a slower, longer animation and not a faster, shorter animation. The easing argument can be changed from its default value of swing to linear, which causes the animation to progress at the same speed throughout the animation. The default, swing, causes the animation to start slowly, speed up slightly, and then slow down towards the end of the animation. The number of easing types can be greatly increased using plugins. We'll look at the extra easing types added by jQuery UI later in the book. We may supply a callback function (either a function reference or an anonymous function, with the latter being more common-place). This callback function will be executed after the animation ends for each element in the selection, so it may be triggered more than once if more than a single element is being animated. jQuery's Unified Animation API In addition to the fading methods looked at in this chapter, it is worth noting at this stage that any of the animation methods exposed by jQuery can accept the strings slow or fast as the value of the duration argument, and they will always equate to durations of 600 or 200 milliseconds, respectively. Any other strings that are supplied will be ignored and will cause the animation to take its default duration of 400 milliseconds (as if no duration argument had been supplied). Any integer, representing an actual length of time in milliseconds, can also be supplied. Additionally, all jQuery animation methods can have easing configured, and all can accept a callback function as an argument. Each of the animation methods work and are used in the same way; it is just the effect which differs. This makes using the methods easy and intuitive.
Fading Animations A useful point to note is that the arguments do not need to all be provided when only the callback function is required. If we don't need to set the duration or easing arguments, we can just supply the callback function and jQuery will still execute it at the end of the animation. Enhancing simple CSS hover states with fadeIn It is standard practice to add hover-states for the items in a navigation menu using CSS, but with jQuery we can progressively enhance simple CSS hover states into full-on animations that give a much more attractive and professional effect when hovered. In this example, we will see how to: Disable standard CSS hovers when JavaScript is enabled Add the additional HTML markup required for the animations Implement attractive fadeIn() animations triggered by hovering We'll end up with a navigation menu in which the hover-states are animated into view instead of being shown instantly, as shown in the following screenshot: [ 22 ]
- Page 2 and 3: Download from Wow! eBook jQuery 1.
- Page 4 and 5: Author Dan Wellman Reviewers Shaifu
- Page 6 and 7: About the Author Dan Wellman is an
- Page 8 and 9: Cyril Pierron is an engineer, a web
- Page 12: For Pat Spacagna, the greatest moth
- Page 15 and 16: Download from Wow! eBook Table of
- Page 17 and 18: Table of Contents Time for action -
- Page 19 and 20: Table of Contents jQuery and transf
- Page 21 and 22: Drawing to the canvas 309 Supportin
- Page 23 and 24: Preface What this book covers Chapt
- Page 25 and 26: Preface Have a go hero - heading Th
- Page 27 and 28: Preface Piracy Piracy of copyright
- Page 29 and 30: Introduction In addition to animate
- Page 31 and 32: Introduction When not to use animat
- Page 33 and 34: Introduction of the template file"
- Page 35 and 36: Introduction In the previous screen
- Page 37 and 38: Introduction Once our variables hav
- Page 40 and 41: 2 Fading Animations In this chapter
- Page 44 and 45: The previous screenshot shows how t
- Page 46 and 47: [ 25 ] Chapter 2 Most of the styles
- Page 48 and 49: 2. What else can be passed into the
- Page 50 and 51: Time for action - creating the dial
- Page 52 and 53: [ 31 ] Chapter 2 For example, the a
- 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
[ 21 ]<br />
Chapter 2<br />
We can control the duration <strong>of</strong> the animation using the duration argument to specify either<br />
an integer in milliseconds or one <strong>of</strong> the strings slow or fast, which are shortcuts for<br />
durations <strong>of</strong> 600 or 200 milliseconds, respectively.<br />
We can also supply 0 as the duration argument, which will effectively disable the animation.<br />
It's unlikely that we'd need to do this as it would be more efficient to not use an animation at<br />
all, but it is useful to know. I should point out that the fade will still occur; it will just happen<br />
over a duration <strong>of</strong> 0 milliseconds.<br />
The duration argument relates to the length <strong>of</strong> time the animation takes to run,<br />
not the speed <strong>of</strong> the animation. Therefore, a higher value will mean a slower,<br />
longer animation and not a faster, shorter animation.<br />
The easing argument can be changed from its default value <strong>of</strong> swing to linear, which<br />
causes the animation to progress at the same speed throughout the animation. The default,<br />
swing, causes the animation to start slowly, speed up slightly, and then slow down towards<br />
the end <strong>of</strong> the animation.<br />
The number <strong>of</strong> easing types can be greatly increased using plugins. We'll look<br />
at the extra easing types added by <strong>jQuery</strong> UI later in the book.<br />
We may supply a callback function (either a function reference or an anonymous function,<br />
with the latter being more common-place). This callback function will be executed after the<br />
animation ends for each element in the selection, so it may be triggered more than once if<br />
more than a single element is being animated.<br />
<strong>jQuery</strong>'s Unified <strong>Animation</strong> API<br />
In addition to the fading methods looked at in this chapter, it is worth noting at this stage<br />
that any <strong>of</strong> the animation methods exposed by <strong>jQuery</strong> can accept the strings slow or fast<br />
as the value <strong>of</strong> the duration argument, and they will always equate to durations <strong>of</strong> 600 or<br />
200 milliseconds, respectively.<br />
Any other strings that are supplied will be ignored and will cause the animation to take its<br />
default duration <strong>of</strong> 400 milliseconds (as if no duration argument had been supplied). Any<br />
integer, representing an actual length <strong>of</strong> time in milliseconds, can also be supplied.<br />
Additionally, all <strong>jQuery</strong> animation methods can have easing configured, and all can accept a<br />
callback function as an argument. Each <strong>of</strong> the animation methods work and are used in the<br />
same way; it is just the effect which differs. This makes using the methods easy and intuitive.