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