3 // overwrite the old show method
\r
4 _show: jQuery.fn.show,
\r
7 * Show all matched elements using a graceful animation and firing an
\r
8 * optional callback after completion.
\r
10 * The height, width, and opacity of each of the matched elements
\r
11 * are changed dynamically according to the specified speed.
\r
13 * @example $("p").show("slow");
\r
15 * @example $("p").show("slow",function(){
\r
16 * alert("Animation Done.");
\r
21 * @param String|Number 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
22 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
23 * @param String easing (optional) easing effect
\r
25 * @see hide(String|Number,Function)
\r
27 show: function(speed,callback){
\r
28 return speed ? this.animate({
\r
29 height: "show", width: "show", opacity: "show"
\r
30 }, speed, callback) : this._show();
\r
33 // Overwrite the old hide method
\r
34 _hide: jQuery.fn.hide,
\r
37 * Hide all matched elements using a graceful animation and firing an
\r
38 * optional callback after completion.
\r
40 * The height, width, and opacity of each of the matched elements
\r
41 * are changed dynamically according to the specified speed.
\r
43 * @example $("p").hide("slow");
\r
45 * @example $("p").hide("slow",function(){
\r
46 * alert("Animation Done.");
\r
51 * @param String|Number 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
52 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
53 * @param String easing (optional) easing effect
\r
55 * @see show(String|Number,Function)
\r
57 hide: function(speed,callback){
\r
58 return speed ? this.animate({
\r
59 height: "hide", width: "hide", opacity: "hide"
\r
60 }, speed, callback) : this._hide();
\r
64 * Reveal all matched elements by adjusting their height and firing an
\r
65 * optional callback after completion.
\r
67 * Only the height is adjusted for this animation, causing all matched
\r
68 * elements to be revealed in a "sliding" manner.
\r
70 * @example $("p").slideDown("slow");
\r
72 * @example $("p").slideDown("slow",function(){
\r
73 * alert("Animation Done.");
\r
78 * @param String|Number speed (optional) 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
79 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
80 * @param String easing (optional) easing effect
\r
82 * @see slideUp(String|Number,Function)
\r
83 * @see slideToggle(String|Number,Function)
\r
85 slideDown: function(speed,callback){
\r
86 return this.animate({height: "show"}, speed, callback);
\r
90 * Hide all matched elements by adjusting their height and firing an
\r
91 * optional callback after completion.
\r
93 * Only the height is adjusted for this animation, causing all matched
\r
94 * elements to be hidden in a "sliding" manner.
\r
96 * @example $("p").slideUp("slow");
\r
98 * @example $("p").slideUp("slow",function(){
\r
99 * alert("Animation Done.");
\r
104 * @param String|Number speed (optional) 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 (optional) A function to be executed whenever the animation completes.
\r
106 * @param String easing (optional) easing effect
\r
108 * @see slideDown(String|Number,Function)
\r
109 * @see slideToggle(String|Number,Function)
\r
111 slideUp: function(speed,callback){
\r
112 return this.animate({height: "hide"}, speed, callback);
\r
116 * Toggle the visibility of all matched elements by adjusting their height and firing an
\r
117 * optional callback after completion.
\r
119 * Only the height is adjusted for this animation, causing all matched
\r
120 * elements to be hidden in a "sliding" manner.
\r
122 * @example $("p").slideToggle("slow");
\r
124 * @example $("p").slideToggle("slow",function(){
\r
125 * alert("Animation Done.");
\r
128 * @name slideToggle
\r
130 * @param String|Number speed (optional) 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
131 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
132 * @param String easing (optional) easing effect
\r
134 * @see slideDown(String|Number,Function)
\r
135 * @see slideUp(String|Number,Function)
\r
137 slideToggle: function(speed, callback){
\r
138 return this.each(function(){
\r
139 var state = jQuery(this).is(":hidden") ? "show" : "hide";
\r
140 jQuery(this).animate({height: state}, speed, callback);
\r
145 * Fade in all matched elements by adjusting their opacity and firing an
\r
146 * optional callback after completion.
\r
148 * Only the opacity is adjusted for this animation, meaning that
\r
149 * all of the matched elements should already have some form of height
\r
150 * and width associated with them.
\r
152 * @example $("p").fadeIn("slow");
\r
154 * @example $("p").fadeIn("slow",function(){
\r
155 * alert("Animation Done.");
\r
160 * @param String|Number speed (optional) 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
161 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
162 * @param String easing (optional) easing effect
\r
164 * @see fadeOut(String|Number,Function)
\r
165 * @see fadeTo(String|Number,Number,Function)
\r
167 fadeIn: function(speed, callback){
\r
168 return this.animate({opacity: "show"}, speed, callback);
\r
172 * Fade out all matched elements by adjusting their opacity and firing an
\r
173 * optional callback after completion.
\r
175 * Only the opacity is adjusted for this animation, meaning that
\r
176 * all of the matched elements should already have some form of height
\r
177 * and width associated with them.
\r
179 * @example $("p").fadeOut("slow");
\r
181 * @example $("p").fadeOut("slow",function(){
\r
182 * alert("Animation Done.");
\r
187 * @param String|Number speed (optional) 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
188 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
189 * @param String easing (optional) easing effect
\r
191 * @see fadeIn(String|Number,Function)
\r
192 * @see fadeTo(String|Number,Number,Function)
\r
194 fadeOut: function(speed, callback){
\r
195 return this.animate({opacity: "hide"}, speed, callback);
\r
199 * Fade the opacity of all matched elements to a specified opacity and firing an
\r
200 * optional callback after completion.
\r
202 * Only the opacity is adjusted for this animation, meaning that
\r
203 * all of the matched elements should already have some form of height
\r
204 * and width associated with them.
\r
206 * @example $("p").fadeTo("slow", 0.5);
\r
208 * @example $("p").fadeTo("slow", 0.5, function(){
\r
209 * alert("Animation Done.");
\r
214 * @param String|Number 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
215 * @param Number opacity The opacity to fade to (a number from 0 to 1).
\r
216 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
217 * @param String easing (optional) easing effect
\r
219 * @see fadeIn(String|Number,Function)
\r
220 * @see fadeOut(String|Number,Function)
\r
222 fadeTo: function(speed,to,callback){
\r
223 return this.animate({opacity: to}, speed, callback);
\r
227 * A function for making your own, custom, animations. The key aspect of
\r
228 * this function is the object of style properties that will be animated,
\r
229 * and to what end. Each key within the object represents a style property
\r
230 * that will also be animated (for example: "height", "top", or "opacity").
\r
232 * The value associated with the key represents to what end the property
\r
233 * will be animated. If a number is provided as the value, then the style
\r
234 * property will be transitioned from its current state to that new number.
\r
235 * Oterwise if the string "hide", "show", or "toggle" is provided, a default
\r
236 * animation will be constructed for that property.
\r
238 * @example $("p").animate({
\r
239 * height: 'toggle', opacity: 'toggle'
\r
242 * @example $("p").animate({
\r
243 * left: 50, opacity: 'show'
\r
248 * @param Hash params A set of style attributes that you wish to animate, and to what end.
\r
249 * @param String|Number speed (optional) 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
250 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
251 * @param String easing (optional) easing effect
\r
254 animate: function( prop, speed, easing, callback ) {
\r
255 return this.queue(function(){
\r
257 this.curAnim = jQuery.extend({}, prop);
258 var opt = jQuery.speed(speed, easing, callback);
\r
260 for ( var p in prop ) {
\r
261 var e = new jQuery.fx( this, opt, p );
\r
262 if ( prop[p].constructor == Number )
\r
263 e.custom( e.cur(), prop[p] );
\r
265 e[ prop[p] ]( prop );
\r
275 queue: function(type,fn){
\r
281 return this.each(function(){
\r
285 if ( !this.queue[type] )
\r
286 this.queue[type] = [];
\r
288 this.queue[type].push( fn );
\r
290 if ( this.queue[type].length == 1 )
\r
299 speed: function(speed, easing, fn) {
\r
300 var opt = speed.constructor == Object ? speed : {
301 complete: fn || !fn && easing ||
302 speed.constructor == Function && speed,
304 easing: fn && easing || easing && easing.constructor != Function && easing
307 opt.duration = (opt.duration.constructor == Number ?
309 { slow: 600, fast: 200 }[opt.duration]) || 400;
\r
312 opt.oldComplete = opt.complete;
\r
313 opt.complete = function(){
\r
314 jQuery.dequeue(this, "fx");
\r
315 if ( opt.oldComplete && opt.oldComplete.constructor == Function )
\r
316 opt.oldComplete.apply( this );
\r
326 dequeue: function(elem,type){
\r
327 type = type || "fx";
\r
329 if ( elem.queue && elem.queue[type] ) {
\r
331 elem.queue[type].shift();
\r
333 // Get next function
\r
334 var f = elem.queue[type][0];
\r
336 if ( f ) f.apply( elem );
\r
341 * I originally wrote fx() as a clone of moo.fx and in the process
\r
342 * of making it small in size the code became illegible to sane
\r
343 * people. You've been warned.
\r
346 fx: function( elem, options, prop ){
\r
351 var y = elem.style;
\r
353 // Store display property
\r
354 var oldDisplay = jQuery.css(elem, 'display');
\r
355 // Set display property to block for animation
\r
356 y.display = "block";
\r
357 // Make sure that nothing sneaks out
\r
358 y.overflow = "hidden";
\r
360 // Simple function for setting a style value
\r
362 if ( options.step )
\r
363 options.step.apply( elem, [ z.now ] );
\r
365 if ( prop == "opacity" )
\r
366 jQuery.attr(y, "opacity", z.now); // Let attr handle opacity
\r
367 else if ( parseInt(z.now) ) // My hate for IE will never die
\r
368 y[prop] = parseInt(z.now) + "px";
\r
371 // Figure out the maximum number to run to
\r
372 z.max = function(){
\r
373 return parseFloat( jQuery.css(elem,prop) );
\r
376 // Get the current size
\r
377 z.cur = function(){
\r
378 var r = parseFloat( jQuery.curCSS(elem, prop) );
\r
379 return r && r > -10000 ? r : z.max();
\r
382 // Start an animation from one number to another
\r
383 z.custom = function(from,to){
\r
384 z.startTime = (new Date()).getTime();
\r
388 z.timer = setInterval(function(){
\r
393 // Simple 'show' function
\r
394 z.show = function(){
\r
395 if ( !elem.orig ) elem.orig = {};
\r
397 // Remember where we started, so that we can go back to it later
\r
398 elem.orig[prop] = this.cur();
\r
400 options.show = true;
\r
402 // Begin the animation
\r
403 z.custom(0, elem.orig[prop]);
\r
405 // Stupid IE, look what you made me do
\r
406 if ( prop != "opacity" )
\r
410 // Simple 'hide' function
\r
411 z.hide = function(){
\r
412 if ( !elem.orig ) elem.orig = {};
\r
414 // Remember where we started, so that we can go back to it later
\r
415 elem.orig[prop] = this.cur();
\r
417 options.hide = true;
\r
419 // Begin the animation
\r
420 z.custom(elem.orig[prop], 0);
\r
423 //Simple 'toggle' function
\r
424 z.toggle = function() {
\r
425 if ( !elem.orig ) elem.orig = {};
\r
427 // Remember where we started, so that we can go back to it later
\r
428 elem.orig[prop] = this.cur();
\r
430 if(oldDisplay == 'none') {
\r
431 options.show = true;
\r
433 // Stupid IE, look what you made me do
\r
434 if ( prop != "opacity" )
\r
437 // Begin the animation
\r
438 z.custom(0, elem.orig[prop]);
\r
440 options.hide = true;
\r
442 // Begin the animation
\r
443 z.custom(elem.orig[prop], 0);
\r
447 // Each step of an animation
\r
448 z.step = function(firstNum, lastNum){
\r
449 var t = (new Date()).getTime();
\r
451 if (t > options.duration + z.startTime) {
\r
453 clearInterval(z.timer);
\r
459 if (elem.curAnim) elem.curAnim[ prop ] = true;
\r
462 for ( var i in elem.curAnim )
\r
463 if ( elem.curAnim[i] !== true )
\r
467 // Reset the overflow
\r
470 // Reset the display
\r
471 y.display = oldDisplay;
\r
472 if (jQuery.css(elem, 'display') == 'none')
\r
473 y.display = 'block';
\r
475 // Hide the element if the "hide" operation was done
\r
476 if ( options.hide )
\r
477 y.display = 'none';
\r
479 // Reset the properties, if the item has been hidden or shown
\r
480 if ( options.hide || options.show )
\r
481 for ( var p in elem.curAnim )
\r
482 if (p == "opacity")
\r
483 jQuery.attr(y, p, elem.orig[p]);
\r
488 // If a callback was provided, execute it
\r
489 if ( done && options.complete && options.complete.constructor == Function )
\r
490 // Execute the complete function
\r
491 options.complete.apply( elem );
\r
493 var n = t - this.startTime;
\r
494 // Figure out where in the animation we are and set the number
\r
495 var p = n / options.duration;
497 // If the easing function exists, then use it
\r
498 z.now = options.easing && jQuery.easing[options.easing] ?
499 jQuery.easing[options.easing](p, n, firstNum, (lastNum-firstNum), options.duration) :
500 // else use default linear easing
501 ((-Math.cos(p*Math.PI)/2) + 0.5) * (lastNum-firstNum) + firstNum;
\r
503 // Perform the next step of the animation
\r