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 = 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 setAuto: function(e,p) {
\r
360 if ( e.notAuto ) return;
\r
362 if ( p == "height" && e.scrollHeight != parseInt(jQuery.curCSS(e,p)) ) return;
\r
363 if ( p == "width" && e.scrollWidth != parseInt(jQuery.curCSS(e,p)) ) return;
\r
365 // Remember the original height
\r
366 var a = e.style[p];
\r
368 // Figure out the size of the height right now
\r
369 var o = jQuery.curCSS(e,p,1);
\r
371 if ( p == "height" && e.scrollHeight != o ||
\r
372 p == "width" && e.scrollWidth != o ) return;
\r
374 // Set the height to auto
\r
375 e.style[p] = e.currentStyle ? "" : "auto";
\r
377 // See what the size of "auto" is
\r
378 var n = jQuery.curCSS(e,p,1);
\r
380 // Revert back to the original size
\r
381 if ( o != n && n != "auto" ) {
\r
387 speed: function(s,o) {
\r
390 if ( o.constructor == Function )
\r
391 o = { complete: o };
\r
393 var ss = { slow: 600, fast: 200 };
\r
394 o.duration = (s && s.constructor == Number ? s : ss[s]) || 400;
\r
397 o.oldComplete = o.complete;
\r
398 o.complete = function(){
\r
399 jQuery.dequeue(this, "fx");
\r
400 if ( o.oldComplete && o.oldComplete.constructor == Function )
\r
401 o.oldComplete.apply( this );
\r
409 dequeue: function(elem,type){
\r
410 type = type || "fx";
\r
412 if ( elem.queue && elem.queue[type] ) {
\r
414 elem.queue[type].shift();
\r
416 // Get next function
\r
417 var f = elem.queue[type][0];
\r
419 if ( f ) f.apply( elem );
\r
424 * I originally wrote fx() as a clone of moo.fx and in the process
\r
425 * of making it small in size the code became illegible to sane
\r
426 * people. You've been warned.
\r
429 fx: function( elem, options, prop ){
\r
433 // The users options
\r
435 duration: options.duration || 400,
\r
436 complete: options.complete,
\r
444 var y = z.el.style;
\r
446 // Simple function for setting a style value
\r
448 if ( options.step )
\r
449 options.step.apply( elem, [ z.now ] );
\r
451 if ( prop == "opacity" )
\r
452 jQuery.attr(y, "opacity", z.now); // Let attr handle opacity
\r
453 else if ( parseInt(z.now) ) // My hate for IE will never die
\r
454 y[prop] = parseInt(z.now) + "px";
\r
456 y.display = "block";
\r
459 // Figure out the maximum number to run to
\r
460 z.max = function(){
\r
461 return parseFloat( jQuery.css(z.el,prop) );
\r
464 // Get the current size
\r
465 z.cur = function(){
\r
466 var r = parseFloat( jQuery.curCSS(z.el, prop) );
\r
467 return r && r > -10000 ? r : z.max();
\r
470 // Start an animation from one number to another
\r
471 z.custom = function(from,to){
\r
472 z.startTime = (new Date()).getTime();
\r
476 z.timer = setInterval(function(){
\r
481 // Simple 'show' function
\r
482 z.show = function( p ){
\r
483 if ( !z.el.orig ) z.el.orig = {};
\r
485 // Remember where we started, so that we can go back to it later
\r
486 z.el.orig[prop] = this.cur();
\r
488 // Begin the animation
\r
489 if (prop == "opacity")
\r
490 z.custom(z.el.orig[prop], 1);
\r
492 z.custom(0, z.el.orig[prop]);
\r
494 // Stupid IE, look what you made me do
\r
495 if ( prop != "opacity" )
\r
499 // Simple 'hide' function
\r
500 z.hide = function(){
\r
501 if ( !z.el.orig ) z.el.orig = {};
\r
503 // Remember where we started, so that we can go back to it later
\r
504 z.el.orig[prop] = this.cur();
\r
508 // Begin the animation
\r
509 z.custom(z.el.orig[prop], 0);
\r
512 // Remember the overflow of the element
\r
513 if ( !z.el.oldOverlay )
\r
514 z.el.oldOverflow = jQuery.css( z.el, "overflow" );
\r
516 // Make sure that nothing sneaks out
\r
517 y.overflow = "hidden";
\r
519 // Each step of an animation
\r
520 z.step = function(firstNum, lastNum){
\r
521 var t = (new Date()).getTime();
\r
523 if (t > z.o.duration + z.startTime) {
\r
525 clearInterval(z.timer);
\r
531 z.el.curAnim[ prop ] = true;
\r
534 for ( var i in z.el.curAnim )
\r
535 if ( z.el.curAnim[i] !== true )
\r
539 // Reset the overflow
\r
540 y.overflow = z.el.oldOverflow;
\r
542 // Hide the element if the "hide" operation was done
\r
544 y.display = 'none';
\r
546 // Reset the property, if the item has been hidden
\r
548 for ( var p in z.el.curAnim ) {
\r
549 if (p == "opacity" && jQuery.browser.msie)
\r
550 jQuery.attr(y, p, z.el.orig[p]);
\r
552 y[ p ] = z.el.orig[p] + "px";
\r
554 // set its height and/or width to auto
\r
555 if ( p == 'height' || p == 'width' )
\r
556 jQuery.setAuto( z.el, p );
\r
561 // If a callback was provided, execute it
\r
562 if( done && z.o.complete && z.o.complete.constructor == Function )
\r
563 // Execute the complete function
\r
564 z.o.complete.apply( z.el );
\r
566 // Figure out where in the animation we are and set the number
\r
567 var p = (t - this.startTime) / z.o.duration;
\r
568 z.now = ((-Math.cos(p*Math.PI)/2) + 0.5) * (lastNum-firstNum) + firstNum;
\r
570 // Perform the next step of the animation
\r