jQuery 1.4 Animation Techniques - Index of
jQuery 1.4 Animation Techniques - Index of jQuery 1.4 Animation Techniques - Index of
[ 47 ] Chapter 2 Usually these methods do not take any arguments, but we can trigger an animation by supplying an additional argument which represents either the duration, or the easing of the animation. We can also add a callback function in keeping with the animation methods we have looked at so far. The methods can take the following format: jQuery(elements).show(duration, [easing], [callback]); jQuery(elements).hide(duration, [easing], [callback]); These animations are a step-up in complexity from simple fading because instead of just animating the opacity of the selected elements, the width and height of the element are animated too. Syntactically, the methods are very similar however. This means that the selected elements will grow in size as they appear, or shrink as they disappear. We have little direct control over this however, and can set only the duration or easing of the animations. The direction in which the selected element will grow or shrink can be manipulated indirectly via CSS however. If the selected element is positioned using its left and top style properties, the animation will proceed from the top-left corner, growing to the right and down. If it is positioned using its right and bottom style properties, it will grow up and to the left instead. When an animation is not proceeding in the way in which you expect, it is always worth ruling out any interference from CSS. Styles can affect how an element is animated, so if you aren't getting errors in the JavaScript console, always check that the CSS isn't the cause of unexpected behavior. I have lost count of the hours spent checking and rechecking scripts, only to find that a tiny tweak to the CSS fixes the problem entirely. Like the fadeIn() method, elements that are to be animated using the show() method should initially be hidden with display:none. Elements being shown will be set to display:block, or whatever other display mode is acceptable for the element in question. Flyout submenus with jQuery's show/hide logic Let's take a look at a basic example of the show() and hide() methods in action. We'll create a simple vertical navigation menu which features fly-out submenus that are animated in and out of view. We'll look at the following aspects of these methods: How to trigger an animation using the show() or hide() methods
Fading Animations Our fly-out menu will be displayed like this: In the previous screenshot, we see the submenu fade in as well as grow outwards as the mouse pointer hovers over a top-level menu item. As before, the animation proceeds from the top to the bottom in the screenshot. [ 48 ]
- 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 42 and 43: [ 21 ] Chapter 2 We can control the
- 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 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 104 and 105: Toggling the slide [ 83 ] Chapter 4
- 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
[ 47 ]<br />
Chapter 2<br />
Usually these methods do not take any arguments, but we can trigger an animation by<br />
supplying an additional argument which represents either the duration, or the easing <strong>of</strong> the<br />
animation. We can also add a callback function in keeping with the animation methods we<br />
have looked at so far.<br />
The methods can take the following format:<br />
<strong>jQuery</strong>(elements).show(duration, [easing], [callback]);<br />
<strong>jQuery</strong>(elements).hide(duration, [easing], [callback]);<br />
These animations are a step-up in complexity from simple fading because instead <strong>of</strong> just<br />
animating the opacity <strong>of</strong> the selected elements, the width and height <strong>of</strong> the element are<br />
animated too. Syntactically, the methods are very similar however.<br />
This means that the selected elements will grow in size as they appear, or shrink as they<br />
disappear. We have little direct control over this however, and can set only the duration<br />
or easing <strong>of</strong> the animations.<br />
The direction in which the selected element will grow or shrink can be manipulated<br />
indirectly via CSS however. If the selected element is positioned using its left and top<br />
style properties, the animation will proceed from the top-left corner, growing to the right<br />
and down. If it is positioned using its right and bottom style properties, it will grow up<br />
and to the left instead.<br />
When an animation is not proceeding in the way in which you expect, it is always worth<br />
ruling out any interference from CSS. Styles can affect how an element is animated, so if<br />
you aren't getting errors in the JavaScript console, always check that the CSS isn't the cause<br />
<strong>of</strong> unexpected behavior. I have lost count <strong>of</strong> the hours spent checking and rechecking scripts,<br />
only to find that a tiny tweak to the CSS fixes the problem entirely.<br />
Like the fadeIn() method, elements that are to be animated using the show() method<br />
should initially be hidden with display:none. Elements being shown will be set to<br />
display:block, or whatever other display mode is acceptable for the element in question.<br />
Flyout submenus with <strong>jQuery</strong>'s show/hide logic<br />
Let's take a look at a basic example <strong>of</strong> the show() and hide() methods in action. We'll<br />
create a simple vertical navigation menu which features fly-out submenus that are animated<br />
in and out <strong>of</strong> view. We'll look at the following aspects <strong>of</strong> these methods:<br />
How to trigger an animation using the show() or hide() methods