3 // overwrite the old show method
7 * Show all matched elements using a graceful animation.
8 * The height, width, and opacity of each of the matched elements
9 * are changed dynamically according to the specified speed.
11 * @example $("p").show("slow");
15 * @param Object speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
16 * @cat Effects/Animations
20 * Show all matched elements using a graceful animation and firing a callback
21 * function after completion.
22 * The height, width, and opacity of each of the matched elements
23 * are changed dynamically according to the specified speed.
25 * @example $("p").show("slow",function(){
26 * alert("Animation Done.");
31 * @param Object speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
32 * @param Function callback A function to be executed whenever the animation completes.
33 * @cat Effects/Animations
35 show: function(speed,callback){
36 return speed ? this.animate({
37 height: "show", width: "show", opacity: "show"
38 }, speed, callback) : this._show();
41 // Overwrite the old hide method
42 _hide: jQuery.fn.hide,
45 * Hide all matched elements using a graceful animation.
46 * The height, width, and opacity of each of the matched elements
47 * are changed dynamically according to the specified speed.
49 * @example $("p").hide("slow");
53 * @param Object speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
54 * @cat Effects/Animations
58 * Hide all matched elements using a graceful animation and firing a callback
59 * function after completion.
60 * The height, width, and opacity of each of the matched elements
61 * are changed dynamically according to the specified speed.
63 * @example $("p").hide("slow",function(){
64 * alert("Animation Done.");
69 * @param Object speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
70 * @param Function callback A function to be executed whenever the animation completes.
71 * @cat Effects/Animations
73 hide: function(speed,callback){
74 return speed ? this.animate({
75 height: "hide", width: "hide", opacity: "hide"
76 }, speed, callback) : this._hide();
80 * Reveal all matched elements by adjusting their height.
81 * Only the height is adjusted for this animation, causing all matched
82 * elements to be revealed in a "sliding" manner.
84 * @example $("p").slideDown("slow");
88 * @param Object speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
89 * @cat Effects/Animations
93 * Reveal all matched elements by adjusting their height and firing a callback
94 * function after completion.
95 * Only the height is adjusted for this animation, causing all matched
96 * elements to be revealed in a "sliding" manner.
98 * @example $("p").slideDown("slow",function(){
99 * alert("Animation Done.");
104 * @param Object speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
105 * @param Function callback A function to be executed whenever the animation completes.
106 * @cat Effects/Animations
108 slideDown: function(speed,callback){
109 return this.animate({height: "show"}, speed, callback);
113 * Hide all matched elements by adjusting their height.
114 * Only the height is adjusted for this animation, causing all matched
115 * elements to be hidden in a "sliding" manner.
117 * @example $("p").slideUp("slow");
121 * @param Object speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
122 * @cat Effects/Animations
126 * Hide all matched elements by adjusting their height and firing a callback
127 * function after completion.
128 * Only the height is adjusted for this animation, causing all matched
129 * elements to be hidden in a "sliding" manner.
131 * @example $("p").slideUp("slow",function(){
132 * alert("Animation Done.");
137 * @param Object speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
138 * @param Function callback A function to be executed whenever the animation completes.
139 * @cat Effects/Animations
141 slideUp: function(speed,callback){
142 return this.animate({height: "hide"}, speed, callback);
146 * Toggle the visibility of all matched elements by adjusting their height.
147 * Only the height is adjusted for this animation, causing all matched
148 * elements to be hidden in a "sliding" manner.
150 * @example $("p").slideToggle("slow");
154 * @param Object speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
155 * @cat Effects/Animations
159 * Toggle the visibility of all matched elements by adjusting their height
160 * and firing a callback function after completion.
161 * Only the height is adjusted for this animation, causing all matched
162 * elements to be hidden in a "sliding" manner.
164 * @example $("p").slideToggle("slow",function(){
165 * alert("Animation Done.");
170 * @param Object speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
171 * @param Function callback A function to be executed whenever the animation completes.
172 * @cat Effects/Animations
174 slideToggle: function(speed,callback){
175 return this.each(function(){
176 var state = jQuery(this).is(":hidden") ? "show" : "hide";
177 jQuery(this).animate({height: state}, speed, callback);
182 * Fade in all matched elements by adjusting their opacity.
183 * Only the opacity is adjusted for this animation, meaning that
184 * all of the matched elements should already have some form of height
185 * and width associated with them.
187 * @example $("p").fadeIn("slow");
191 * @param Object speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
192 * @cat Effects/Animations
196 * Fade in all matched elements by adjusting their opacity and firing a
197 * callback function after completion.
198 * Only the opacity is adjusted for this animation, meaning that
199 * all of the matched elements should already have some form of height
200 * and width associated with them.
202 * @example $("p").fadeIn("slow",function(){
203 * alert("Animation Done.");
208 * @param Object speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
209 * @param Function callback A function to be executed whenever the animation completes.
210 * @cat Effects/Animations
212 fadeIn: function(speed,callback){
213 return this.animate({opacity: "show"}, speed, callback);
217 * Fade out all matched elements by adjusting their opacity.
218 * Only the opacity is adjusted for this animation, meaning that
219 * all of the matched elements should already have some form of height
220 * and width associated with them.
222 * @example $("p").fadeOut("slow");
226 * @param Object speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
227 * @cat Effects/Animations
231 * Fade out all matched elements by adjusting their opacity and firing a
232 * callback function after completion.
233 * Only the opacity is adjusted for this animation, meaning that
234 * all of the matched elements should already have some form of height
235 * and width associated with them.
237 * @example $("p").fadeOut("slow",function(){
238 * alert("Animation Done.");
243 * @param Object speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
244 * @param Function callback A function to be executed whenever the animation completes.
245 * @cat Effects/Animations
247 fadeOut: function(speed,callback){
248 return this.animate({opacity: "hide"}, speed, callback);
252 * Fade the opacity of all matched elements to a specified opacity.
253 * Only the opacity is adjusted for this animation, meaning that
254 * all of the matched elements should already have some form of height
255 * and width associated with them.
257 * @example $("p").fadeTo("slow", 0.5);
261 * @param Object speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
262 * @param Number opacity The opacity to fade to (a number from 0 to 1).
263 * @cat Effects/Animations
267 * Fade the opacity of all matched elements to a specified opacity and
268 * firing a callback function after completion.
269 * Only the opacity is adjusted for this animation, meaning that
270 * all of the matched elements should already have some form of height
271 * and width associated with them.
273 * @example $("p").fadeTo("slow", 0.5, function(){
274 * alert("Animation Done.");
279 * @param Object speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
280 * @param Number opacity The opacity to fade to (a number from 0 to 1).
281 * @param Function callback A function to be executed whenever the animation completes.
282 * @cat Effects/Animations
284 fadeTo: function(speed,to,callback){
285 return this.animate({opacity: to}, speed, callback);
289 * A function for making your own, custom, animations. The key aspect of
290 * this function is the object of style properties that will be animated,
291 * and to what end. Each key within the object represents a style property
292 * that will also be animated (for example: "height", "top", or "opacity").
294 * The value associated with the key represents to what end the property
295 * will be animated. If a number is provided as the value, then the style
296 * property will be transitioned from its current state to that new number.
297 * Oterwise if the string "hide", "show", or "toggle" is provided, a default
298 * animation will be constructed for that property.
300 * @example $("p").animate({
301 * height: 'toggle', opacity: 'toggle'
304 * @example $("p").animate({
305 * left: 50, opacity: 'show'
310 * @param Hash params A set of style attributes that you wish to animate, and to what end.
311 * @param Object speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
312 * @param Function callback A function to be executed whenever the animation completes.
313 * @cat Effects/Animations
315 animate: function(prop,speed,callback) {
316 return this.queue(function(){
318 this.curAnim = jQuery.extend({}, prop);
320 for ( var p in prop ) {
321 var e = new jQuery.fx( this, jQuery.speed(speed,callback), p );
322 if ( prop[p].constructor == Number )
323 e.custom( e.cur(), prop[p] );
325 e[ prop[p] ]( prop );
335 queue: function(type,fn){
341 return this.each(function(){
345 if ( !this.queue[type] )
346 this.queue[type] = [];
348 this.queue[type].push( fn );
350 if ( this.queue[type].length == 1 )
359 speed: function(s,o) {
362 if ( o.constructor == Function )
365 var ss = { slow: 600, fast: 200 };
366 o.duration = (s && s.constructor == Number ? s : ss[s]) || 400;
369 o.oldComplete = o.complete;
370 o.complete = function(){
371 jQuery.dequeue(this, "fx");
372 if ( o.oldComplete && o.oldComplete.constructor == Function )
373 o.oldComplete.apply( this );
381 dequeue: function(elem,type){
384 if ( elem.queue && elem.queue[type] ) {
386 elem.queue[type].shift();
389 var f = elem.queue[type][0];
391 if ( f ) f.apply( elem );
396 * I originally wrote fx() as a clone of moo.fx and in the process
397 * of making it small in size the code became illegible to sane
398 * people. You've been warned.
401 fx: function( elem, options, prop ){
407 duration: options.duration || 400,
408 complete: options.complete,
418 // Store display property
419 var oldDisplay = jQuery.css(z.el, 'display');
420 // Set display property to block for animation
422 // Make sure that nothing sneaks out
423 y.overflow = "hidden";
425 // Simple function for setting a style value
428 options.step.apply( elem, [ z.now ] );
430 if ( prop == "opacity" )
431 jQuery.attr(y, "opacity", z.now); // Let attr handle opacity
432 else if ( parseInt(z.now) ) // My hate for IE will never die
433 y[prop] = parseInt(z.now) + "px";
436 // Figure out the maximum number to run to
438 return parseFloat( jQuery.css(z.el,prop) );
441 // Get the current size
443 var r = parseFloat( jQuery.curCSS(z.el, prop) );
444 return r && r > -10000 ? r : z.max();
447 // Start an animation from one number to another
448 z.custom = function(from,to){
449 z.startTime = (new Date()).getTime();
453 z.timer = setInterval(function(){
458 // Simple 'show' function
460 if ( !z.el.orig ) z.el.orig = {};
462 // Remember where we started, so that we can go back to it later
463 z.el.orig[prop] = this.cur();
467 // Begin the animation
468 z.custom(0, z.el.orig[prop]);
470 // Stupid IE, look what you made me do
471 if ( prop != "opacity" )
475 // Simple 'hide' function
477 if ( !z.el.orig ) z.el.orig = {};
479 // Remember where we started, so that we can go back to it later
480 z.el.orig[prop] = this.cur();
484 // Begin the animation
485 z.custom(z.el.orig[prop], 0);
488 // Each step of an animation
489 z.step = function(firstNum, lastNum){
490 var t = (new Date()).getTime();
492 if (t > z.o.duration + z.startTime) {
494 clearInterval(z.timer);
500 z.el.curAnim[ prop ] = true;
503 for ( var i in z.el.curAnim )
504 if ( z.el.curAnim[i] !== true )
508 // Reset the overflow
512 y.display = oldDisplay;
513 if (jQuery.css(z.el, 'display') == 'none')
516 // Hide the element if the "hide" operation was done
520 // Reset the properties, if the item has been hidden or shown
521 if ( z.o.hide || z.o.show )
522 for ( var p in z.el.curAnim )
524 jQuery.attr(y, p, z.el.orig[p]);
529 // If a callback was provided, execute it
530 if( done && z.o.complete && z.o.complete.constructor == Function )
531 // Execute the complete function
532 z.o.complete.apply( z.el );
534 // Figure out where in the animation we are and set the number
535 var p = (t - this.startTime) / z.o.duration;
536 z.now = ((-Math.cos(p*Math.PI)/2) + 0.5) * (lastNum-firstNum) + firstNum;
538 // Perform the next step of the animation