Paragraph
Paragraph
$("p").animate ({ "background-color" : "black", color : "white" }, 10000); Figure 14-13 The two paragraphs before applying the effect 220 | Chapter 14: Visual Effects in jQuery UI www.it-ebooks.info Figure 14-14 Changing colors with the animate () method: intermediate step Figure 14-15 Changing colors with the animate () method: final result New Values for the easing Option The jQuery animate () method supports the linear and swing values for the easing option Remember that this option specifies how to progress into the effect: faster at first, faster at the end, and so on The new values of the easing option are shown in Figures 14-16 and 14-17 provided on the jQuery UI official site (http://jqueryui.com/docs/effect/easing) The curve allows you to view how to progress in the effect Producing Effects with CSS Classes jQuery methods for managing CSS classes have been improved in jQuery UI to manage the visual effects Producing Effects with CSS Classes | 221 www.it-ebooks.info Figure 14-16 Values for the easing option (1) The addClass (), removeClass (), and toggleClass () Improved Methods jQuery UI has also improved the addClass (), removeClass (), and toggleClass () methods provided by jQuery The options for these classes are listed in Table 14-14 The new form of the addClass () method is: $(selector, context).addClass (className, duration, easing, callback); The new form of the removeClass () method is: $(selector, context).removeClass (className, duration, easing, callback); The new form of the toggleClass () method is: $(selector, context).toggleClass (className, addOrRemove, duration, easing, callback); 222 | Chapter 14: Visual Effects in jQuery UI www.it-ebooks.info Figure 14-17 Values for the easing option (2) Table 14-14 The toggleClass () method parameters Parameter Function className String containing one or more CSS classes (separated by spaces) duration Indicates the number of milliseconds of the effect A value of takes the element directly in the new style, without progressivity easing Indicates the way to progress in the effect callback callback () method called for each element when the effect is complete for this element This value in addOrRemove Optional Boolean indicating whether to add the CSS class (if true) or delete it (if false) If not specified, the CSS is removed if present the function represents the DOM element for which the effect is complete The switchClass () Method In addition to the improvement of the addClass (), removeClass (), and toggleClass () methods, jQuery UI includes a new switchClass () method to move from one CSS class to another Producing Effects with CSS Classes | 223 www.it-ebooks.info The switchClass () method has the following form: $(selector, context) switchClass (classNameRemoved,classNameAdded, duration, easing, callback); Example of Using the toggleClass () Method Here is an example of using toggleClass () method The Toggle button allows you to add or remove a CSS class (here, class1) on each paragraph by producing an effect Once the new style is applied (after the first click), click the button again to restore the original style (Figures 14-18 and 14-19) The CSS border-style property is not scalable, and it is not integrated into the CSS class: class1 { border-width : 10px; border-color : red; background-color : black; color : white; } ToggleParagraph
Paragraph
function toggle () { $("p").toggleClass ("class1", 1000); } 224 | Chapter 14: Visual Effects in jQuery UI www.it-ebooks.info Figure 14-18 Using the toggleClass () method: before clicking the Toggle button Figure 14-19 Using the toggleClass () method: after clicking the Toggle button Producing Effects with CSS Classes | 225 www.it-ebooks.info www.it-ebooks.info About the Author Eric Sarrion has written about Rails, HTML and CSS, J2EE, and JavaScript for O’Reilly France He manages a small training and development company www.it-ebooks.info www.it-ebooks.info ... manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in this book, and O’Reilly Media, Inc was aware of a trademark claim, the designations have... clicks a tab, jQuery UI will automatically and transparently manage the switch to that tab 12 | Chapter 2: Tabs www.it-ebooks.info Figure 2-2 The tabs are not displayed in the HTML page as expected... options.ajaxOptions.data allows you to specify parameters to the server Managing events associated with tabs Some options are used for tab management, such as selecting, adding, and deleting tabs