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 * @cat Effects/Animations
\r
24 * @see hide(String|Number,Function)
\r
26 show: function(speed,callback){
\r
27 return speed ? this.animate({
\r
28 height: "show", width: "show", opacity: "show"
\r
29 }, speed, callback) : this._show();
\r
32 // Overwrite the old hide method
\r
33 _hide: jQuery.fn.hide,
\r
36 * Hide all matched elements using a graceful animation and firing an
\r
37 * optional callback after completion.
\r
39 * The height, width, and opacity of each of the matched elements
\r
40 * are changed dynamically according to the specified speed.
\r
42 * @example $("p").hide("slow");
\r
44 * @example $("p").hide("slow",function(){
\r
45 * alert("Animation Done.");
\r
50 * @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
51 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
52 * @cat Effects/Animations
\r
53 * @see show(String|Number,Function)
\r
55 hide: function(speed,callback){
\r
56 return speed ? this.animate({
\r
57 height: "hide", width: "hide", opacity: "hide"
\r
58 }, speed, callback) : this._hide();
\r
62 * Reveal all matched elements by adjusting their height and firing an
\r
63 * optional callback after completion.
\r
65 * Only the height is adjusted for this animation, causing all matched
\r
66 * elements to be revealed in a "sliding" manner.
\r
68 * @example $("p").slideDown("slow");
\r
70 * @example $("p").slideDown("slow",function(){
\r
71 * alert("Animation Done.");
\r
76 * @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
77 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
78 * @cat Effects/Animations
\r
79 * @see slideUp(String|Number,Function)
\r
80 * @see slideToggle(String|Number,Function)
\r
82 slideDown: function(speed,callback){
\r
83 return this.animate({height: "show"}, speed, callback);
\r
87 * Hide all matched elements by adjusting their height and firing an
\r
88 * optional callback after completion.
\r
90 * Only the height is adjusted for this animation, causing all matched
\r
91 * elements to be hidden in a "sliding" manner.
\r
93 * @example $("p").slideUp("slow");
\r
95 * @example $("p").slideUp("slow",function(){
\r
96 * alert("Animation Done.");
\r
101 * @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
102 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
103 * @cat Effects/Animations
\r
104 * @see slideDown(String|Number,Function)
\r
105 * @see slideToggle(String|Number,Function)
\r
107 slideUp: function(speed,callback){
\r
108 return this.animate({height: "hide"}, speed, callback);
\r
112 * Toggle the visibility of all matched elements by adjusting their height and firing an
\r
113 * optional callback after completion.
\r
115 * Only the height is adjusted for this animation, causing all matched
\r
116 * elements to be hidden in a "sliding" manner.
\r
118 * @example $("p").slideToggle("slow");
\r
120 * @example $("p").slideToggle("slow",function(){
\r
121 * alert("Animation Done.");
\r
124 * @name slideToggle
\r
126 * @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
127 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
128 * @cat Effects/Animations
\r
129 * @see slideDown(String|Number,Function)
\r
130 * @see slideUp(String|Number,Function)
\r
132 slideToggle: function(speed,callback){
\r
133 return this.each(function(){
\r
134 var state = jQuery(this).is(":hidden") ? "show" : "hide";
\r
135 jQuery(this).animate({height: state}, speed, callback);
\r
140 * Fade in all matched elements by adjusting their opacity and firing an
\r
141 * optional callback after completion.
\r
143 * Only the opacity is adjusted for this animation, meaning that
\r
144 * all of the matched elements should already have some form of height
\r
145 * and width associated with them.
\r
147 * @example $("p").fadeIn("slow");
\r
149 * @example $("p").fadeIn("slow",function(){
\r
150 * alert("Animation Done.");
\r
155 * @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
156 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
157 * @cat Effects/Animations
\r
158 * @see fadeOut(String|Number,Function)
\r
159 * @see fadeTo(String|Number,Number,Function)
\r
161 fadeIn: function(speed,callback){
\r
162 return this.animate({opacity: "show"}, speed, callback);
\r
166 * Fade out all matched elements by adjusting their opacity and firing an
\r
167 * optional callback after completion.
\r
169 * Only the opacity is adjusted for this animation, meaning that
\r
170 * all of the matched elements should already have some form of height
\r
171 * and width associated with them.
\r
173 * @example $("p").fadeOut("slow");
\r
175 * @example $("p").fadeOut("slow",function(){
\r
176 * alert("Animation Done.");
\r
181 * @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
182 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
183 * @cat Effects/Animations
\r
184 * @see fadeIn(String|Number,Function)
\r
185 * @see fadeTo(String|Number,Number,Function)
\r
187 fadeOut: function(speed,callback){
\r
188 return this.animate({opacity: "hide"}, speed, callback);
\r
192 * Fade the opacity of all matched elements to a specified opacity and firing an
\r
193 * optional callback after completion.
\r
195 * Only the opacity is adjusted for this animation, meaning that
\r
196 * all of the matched elements should already have some form of height
\r
197 * and width associated with them.
\r
199 * @example $("p").fadeTo("slow", 0.5);
\r
201 * @example $("p").fadeTo("slow", 0.5, function(){
\r
202 * alert("Animation Done.");
\r
207 * @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
208 * @param Number opacity The opacity to fade to (a number from 0 to 1).
\r
209 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
210 * @cat Effects/Animations
\r
211 * @see fadeIn(String|Number,Function)
\r
212 * @see fadeOut(String|Number,Function)
\r
214 fadeTo: function(speed,to,callback){
\r
215 return this.animate({opacity: to}, speed, callback);
\r
219 * A function for making your own, custom, animations. The key aspect of
\r
220 * this function is the object of style properties that will be animated,
\r
221 * and to what end. Each key within the object represents a style property
\r
222 * that will also be animated (for example: "height", "top", or "opacity").
\r
224 * The value associated with the key represents to what end the property
\r
225 * will be animated. If a number is provided as the value, then the style
\r
226 * property will be transitioned from its current state to that new number.
\r
227 * Oterwise if the string "hide", "show", or "toggle" is provided, a default
\r
228 * animation will be constructed for that property.
\r
230 * @example $("p").animate({
\r
231 * height: 'toggle', opacity: 'toggle'
\r
234 * @example $("p").animate({
\r
235 * left: 50, opacity: 'show'
\r
240 * @param Hash params A set of style attributes that you wish to animate, and to what end.
\r
241 * @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
242 * @param Function callback A function to be executed whenever the animation completes.
\r
243 * @cat Effects/Animations
\r
245 animate: function(prop,speed,callback) {
\r
246 return this.queue(function(){
\r
248 this.curAnim = jQuery.extend({}, prop);
\r
250 for ( var p in prop ) {
\r
251 var e = new jQuery.fx( this, jQuery.speed(speed,callback), p );
\r
252 if ( prop[p].constructor == Number )
\r
253 e.custom( e.cur(), prop[p] );
\r
255 e[ prop[p] ]( prop );
\r
265 queue: function(type,fn){
\r
271 return this.each(function(){
\r
275 if ( !this.queue[type] )
\r
276 this.queue[type] = [];
\r
278 this.queue[type].push( fn );
\r
280 if ( this.queue[type].length == 1 )
\r
289 speed: function(s,o) {
\r
292 if ( o.constructor == Function )
\r
293 o = { complete: o };
\r
295 var ss = { slow: 600, fast: 200 };
\r
296 o.duration = (s && s.constructor == Number ? s : ss[s]) || 400;
\r
299 o.oldComplete = o.complete;
\r
300 o.complete = function(){
\r
301 jQuery.dequeue(this, "fx");
\r
302 if ( o.oldComplete && o.oldComplete.constructor == Function )
\r
303 o.oldComplete.apply( this );
\r
311 dequeue: function(elem,type){
\r
312 type = type || "fx";
\r
314 if ( elem.queue && elem.queue[type] ) {
\r
316 elem.queue[type].shift();
\r
318 // Get next function
\r
319 var f = elem.queue[type][0];
\r
321 if ( f ) f.apply( elem );
\r
326 * I originally wrote fx() as a clone of moo.fx and in the process
\r
327 * of making it small in size the code became illegible to sane
\r
328 * people. You've been warned.
\r
331 fx: function( elem, options, prop ){
\r
335 // The users options
\r
337 duration: options.duration || 400,
\r
338 complete: options.complete,
\r
346 var y = z.el.style;
\r
348 // Store display property
\r
349 var oldDisplay = jQuery.css(z.el, 'display');
\r
350 // Set display property to block for animation
\r
351 y.display = "block";
\r
352 // Make sure that nothing sneaks out
\r
353 y.overflow = "hidden";
\r
355 // Simple function for setting a style value
\r
357 if ( options.step )
\r
358 options.step.apply( elem, [ z.now ] );
\r
360 if ( prop == "opacity" )
\r
361 jQuery.attr(y, "opacity", z.now); // Let attr handle opacity
\r
362 else if ( parseInt(z.now) ) // My hate for IE will never die
\r
363 y[prop] = parseInt(z.now) + "px";
\r
366 // Figure out the maximum number to run to
\r
367 z.max = function(){
\r
368 return parseFloat( jQuery.css(z.el,prop) );
\r
371 // Get the current size
\r
372 z.cur = function(){
\r
373 var r = parseFloat( jQuery.curCSS(z.el, prop) );
\r
374 return r && r > -10000 ? r : z.max();
\r
377 // Start an animation from one number to another
\r
378 z.custom = function(from,to){
\r
379 z.startTime = (new Date()).getTime();
\r
383 z.timer = setInterval(function(){
\r
388 // Simple 'show' function
\r
389 z.show = function(){
\r
390 if ( !z.el.orig ) z.el.orig = {};
\r
392 // Remember where we started, so that we can go back to it later
\r
393 z.el.orig[prop] = this.cur();
\r
397 // Begin the animation
\r
398 z.custom(0, z.el.orig[prop]);
\r
400 // Stupid IE, look what you made me do
\r
401 if ( prop != "opacity" )
\r
405 // Simple 'hide' function
\r
406 z.hide = function(){
\r
407 if ( !z.el.orig ) z.el.orig = {};
\r
409 // Remember where we started, so that we can go back to it later
\r
410 z.el.orig[prop] = this.cur();
\r
414 // Begin the animation
\r
415 z.custom(z.el.orig[prop], 0);
\r
418 //Simple 'toggle' function
\r
419 z.toggle = function() {
\r
420 if ( !z.el.orig ) z.el.orig = {};
\r
422 // Remember where we started, so that we can go back to it later
\r
423 z.el.orig[prop] = this.cur();
\r
425 if(oldDisplay == 'none') {
\r
428 // Stupid IE, look what you made me do
\r
429 if ( prop != "opacity" )
\r
432 // Begin the animation
\r
433 z.custom(0, z.el.orig[prop]);
\r
437 // Begin the animation
\r
438 z.custom(z.el.orig[prop], 0);
\r
442 // Each step of an animation
\r
443 z.step = function(firstNum, lastNum){
\r
444 var t = (new Date()).getTime();
\r
446 if (t > z.o.duration + z.startTime) {
\r
448 clearInterval(z.timer);
\r
454 if (z.el.curAnim) z.el.curAnim[ prop ] = true;
\r
457 for ( var i in z.el.curAnim )
\r
458 if ( z.el.curAnim[i] !== true )
\r
462 // Reset the overflow
\r
465 // Reset the display
\r
466 y.display = oldDisplay;
\r
467 if (jQuery.css(z.el, 'display') == 'none')
\r
468 y.display = 'block';
\r
470 // Hide the element if the "hide" operation was done
\r
472 y.display = 'none';
\r
474 // Reset the properties, if the item has been hidden or shown
\r
475 if ( z.o.hide || z.o.show )
\r
476 for ( var p in z.el.curAnim )
\r
477 if (p == "opacity")
\r
478 jQuery.attr(y, p, z.el.orig[p]);
\r
483 // If a callback was provided, execute it
\r
484 if( done && z.o.complete && z.o.complete.constructor == Function )
\r
485 // Execute the complete function
\r
486 z.o.complete.apply( z.el );
\r
488 // Figure out where in the animation we are and set the number
\r
489 var p = (t - this.startTime) / z.o.duration;
\r
490 z.now = ((-Math.cos(p*Math.PI)/2) + 0.5) * (lastNum-firstNum) + firstNum;
\r
492 // Perform the next step of the animation
\r