jQuery 1.4 Animation Techniques - Index of
jQuery 1.4 Animation Techniques - Index of jQuery 1.4 Animation Techniques - Index of
Time for action – creating the dialog [ 29 ] Chapter 2 We'll start again by creating the underlying markup that the dialog is built with and add any necessary styling. 1. First, add the following code to the in a fresh copy of the template file: A dialog box of some description Lorem ipsum etc, etc. Ok 2. We'll also need to link to a stylesheet in the of the page: 3. Save this page as fadeOut.html in the main project folder. The code for the stylesheet is as follows: #dialog { background-color:#fff; width:300px; padding:10px; font:normal 14px "Nimbus Sans L", "Helvetica Neue", "Franklin Gothic Medium", Sans-serif; border:1px solid #aaa; -moz-border-radius:7px; -webkit-border-radius:7px; border-radius:7px; -moz-box-shadow:2px 2px 5px #000; -webkit-box-shadow:2px 2px 5px #000; box-shadow:2px 2px 5px #000; } #dialog:after { content:""; height:0; display:block; clear:both; visibility:hidden; } #dialog header { display:block; padding-bottom:5px; margin-bottom:10px; font-weight:bold; font-size:16px; border-bottom:1px solid #aaa; } #dialog footer { display:block; padding-top:10px; margin-top:10px; border-top:1px solid #aaa; } #dialog button { float:right; }
Fading Animations 4. Save this in the css folder as fadeOut.css. To perform the fadeOut() animation, we'll need just a tiny bit of JavaScript. Inside the anonymous function in the second element at the bottom of the , add the following code: $("#overlay button").click(function() { $("#overlay").fadeOut(500, function() { $(this).remove(); }); }); What just happened? In our code, we attach a click handler to the using jQuery's click() helper method. The anonymous function we specify as an argument is executed whenever the button is clicked. Within this function we select the dialog using its id and call the fadeOut() method on it using a numerical argument of 500 milliseconds instead of one of the acceptable strings. We also specify a callback function as the second argument to the fadeOut() method. As there is only a single element in the selection (the element with an id of overlay), this function will be executed only once. Inside this callback function, the this keyword is set to the current element, so we can easily manipulate it from within the callback. All the function does is remove the dialog from the DOM. This behavior would be appropriate when the element to be removed was a one-time-only dialog that would either not be shown again during the current session, or would be generated again from scratch by the system when required. We'll see the dialog when we load the page. In a proper implementation, it would probably be centered in the viewport and be absolutely positioned so that it appears to float above the page (additionally the CSS3 shadow that we used would reinforce this impression). It would also more than likely be modal, so the underlying page would be obscured, or otherwise shielded from interaction, until the dialog is closed. To avoid unnecessary cluttering of the example however, our dialog is alone on an empty page. Clicking the will cause the dialog to fade away and then be removed from the page. The animation is fairly quick and less jarring than instantaneous removal of the dialog, but I should point out that fading animations can often annoy users if they are too frequent, take too long to complete, or are felt to be completely unnecessary. [ 30 ]
- 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 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 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
Time for action – creating the dialog<br />
[ 29 ]<br />
Chapter 2<br />
We'll start again by creating the underlying markup that the dialog is built with and add any<br />
necessary styling.<br />
1. First, add the following code to the in a fresh copy <strong>of</strong> the template file:<br />
<br />
A dialog box <strong>of</strong> some description<br />
Lorem ipsum etc, etc.<br />
Ok<br />
<br />
2. We'll also need to link to a stylesheet in the <strong>of</strong> the page:<br />
<br />
3. Save this page as fadeOut.html in the main project folder. The code for the<br />
stylesheet is as follows:<br />
#dialog {<br />
background-color:#fff; width:300px; padding:10px;<br />
font:normal 14px "Nimbus Sans L", "Helvetica Neue", "Franklin<br />
Gothic Medium", Sans-serif;<br />
border:1px solid #aaa; -moz-border-radius:7px;<br />
-webkit-border-radius:7px; border-radius:7px;<br />
-moz-box-shadow:2px 2px 5px #000;<br />
-webkit-box-shadow:2px 2px 5px #000;<br />
box-shadow:2px 2px 5px #000;<br />
}<br />
#dialog:after {<br />
content:""; height:0; display:block; clear:both;<br />
visibility:hidden;<br />
}<br />
#dialog header {<br />
display:block; padding-bottom:5px; margin-bottom:10px;<br />
font-weight:bold; font-size:16px; border-bottom:1px solid #aaa;<br />
}<br />
#dialog footer {<br />
display:block; padding-top:10px; margin-top:10px;<br />
border-top:1px solid #aaa;<br />
}<br />
#dialog button { float:right; }