jQuery 1.4 Animation Techniques - Index of
jQuery 1.4 Animation Techniques - Index of jQuery 1.4 Animation Techniques - Index of
Pop quiz – sliding elements down 1. What should be applied to an element before it has the slideDown() method called on it? a. visibility:hidden; b. height:0; c. display:none; d. position:static; [ 79 ] Chapter 4 2. What style does an element that has been shown with slideDown() end up with? a. display:block; b. visibility:visible; c. position:absolute; d. height:100%; Have a go hero – sliding elements down In our basic example, once the form has been opened it then stays open until the page is reloaded. Add some additional code that fades the login form away after a specified length of time in case it is not interacted with. Sliding elements out of view The slideUp() method works in exactly the same way as slideDown(), except that it hides the target element instead of showing it. The slideUp() method accepts the same arguments as slideDown() and can be affected by CSS in the same way, so padding and margin should be taken into account and caution is advised when using absolute positioning. The original value of an element's display property however, is not a factor when using slideUp(). The method's pattern of usage is as follows: jQuery(elements).slideUp([duration], [easing], [callback]);
Sliding Animations Time for action – sliding elements up Let's build on the previous example so that the form slides back up out of view if a cancel link is clicked. We can add this link to the underlying markup for the page: 1. In slideDown.html, change the form so that it appears as follows (new code is highlighted): Login Form Username: Password: Remember me: Cancel Login 2. Save the new file as slideUp.html. 3. We'll also need some more styles in order to stop our new link from picking up the styling of the login link. At the end of the slideDown.css stylesheet, add the following new selectors and rules: header ul li a#cancel { margin:0; padding:0; position:absolute; bottom:14px; left:10px; font-size:11px; color:#993333; } header ul li a#cancel:hover, header ul li a#cancel:focus { border:none; text-decoration:underline; color:#ff0000; } 4. Save the updated file in the css folder as slideUp.css, and update the in the of slideUp.html to point to the new stylesheet. 5. To add the new behavior, update the at the bottom of the page so that it includes the following new code: $("#cancel").click(function(e) { e.preventDefault(); $(this).closest("form").slideUp(function() { [ 80 ]
- 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
- 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 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
- 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
Pop quiz – sliding elements down<br />
1. What should be applied to an element before it has the slideDown() method<br />
called on it?<br />
a. visibility:hidden;<br />
b. height:0;<br />
c. display:none;<br />
d. position:static;<br />
[ 79 ]<br />
Chapter 4<br />
2. What style does an element that has been shown with slideDown() end up with?<br />
a. display:block;<br />
b. visibility:visible;<br />
c. position:absolute;<br />
d. height:100%;<br />
Have a go hero – sliding elements down<br />
In our basic example, once the form has been opened it then stays open until the page is<br />
reloaded. Add some additional code that fades the login form away after a specified length<br />
<strong>of</strong> time in case it is not interacted with.<br />
Sliding elements out <strong>of</strong> view<br />
The slideUp() method works in exactly the same way as slideDown(), except that it<br />
hides the target element instead <strong>of</strong> showing it. The slideUp() method accepts the same<br />
arguments as slideDown() and can be affected by CSS in the same way, so padding<br />
and margin should be taken into account and caution is advised when using absolute<br />
positioning. The original value <strong>of</strong> an element's display property however, is not a factor<br />
when using slideUp().<br />
The method's pattern <strong>of</strong> usage is as follows:<br />
<strong>jQuery</strong>(elements).slideUp([duration], [easing], [callback]);