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
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
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 (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
77 * @param Function callback (optional) A function to be executed whenever the animation completes.
\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 (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
102 * @param Function callback (optional) A function to be executed whenever the animation completes.
\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 (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
127 * @param Function callback (optional) A function to be executed whenever the animation completes.
\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 (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
156 * @param Function callback (optional) A function to be executed whenever the animation completes.
\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 (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
182 * @param Function callback (optional) A function to be executed whenever the animation completes.
\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
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
238 * @example $("p").animate({
\r
240 * }, "slow", "easein");
241 * @desc An example of using an 'easing' function to provide a different style of animation. This will only work if you have a plugin that provides this easing function (Only 'linear' is provided by default, with jQuery).
\r
245 * @param Hash params A set of style attributes that you wish to animate, and to what end.
\r
246 * @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).
247 * @param String easing (optional) The name of the easing effect that you want to use (Plugin Required).
\r
248 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
251 animate: function( prop, speed, easing, callback ) {
\r
252 return this.queue(function(){
\r
254 this.curAnim = jQuery.extend({}, prop);
255 var opt = jQuery.speed(speed, easing, callback);
\r
257 for ( var p in prop ) {
\r
258 var e = new jQuery.fx( this, opt, p );
\r
259 if ( prop[p].constructor == Number )
\r
260 e.custom( e.cur(), prop[p] );
\r
262 e[ prop[p] ]( prop );
\r
272 queue: function(type,fn){
\r
278 return this.each(function(){
\r
282 if ( !this.queue[type] )
\r
283 this.queue[type] = [];
\r
285 this.queue[type].push( fn );
\r
287 if ( this.queue[type].length == 1 )
\r
296 speed: function(speed, easing, fn) {
\r
297 var opt = speed.constructor == Object ? speed : {
298 complete: fn || !fn && easing ||
299 speed.constructor == Function && speed,
301 easing: fn && easing || easing && easing.constructor != Function && easing
304 opt.duration = (opt.duration.constructor == Number ?
306 { slow: 600, fast: 200 }[opt.duration]) || 400;
\r
309 opt.oldComplete = opt.complete;
\r
310 opt.complete = function(){
\r
311 jQuery.dequeue(this, "fx");
\r
312 if ( opt.oldComplete && opt.oldComplete.constructor == Function )
\r
313 opt.oldComplete.apply( this );
\r
323 dequeue: function(elem,type){
\r
324 type = type || "fx";
\r
326 if ( elem.queue && elem.queue[type] ) {
\r
328 elem.queue[type].shift();
\r
330 // Get next function
\r
331 var f = elem.queue[type][0];
\r
333 if ( f ) f.apply( elem );
\r
338 * I originally wrote fx() as a clone of moo.fx and in the process
\r
339 * of making it small in size the code became illegible to sane
\r
340 * people. You've been warned.
\r
343 fx: function( elem, options, prop ){
\r
348 var y = elem.style;
\r
350 // Store display property
\r
351 var oldDisplay = jQuery.css(elem, 'display');
\r
352 // Set display property to block for animation
\r
353 y.display = "block";
\r
354 // Make sure that nothing sneaks out
\r
355 y.overflow = "hidden";
\r
357 // Simple function for setting a style value
\r
359 if ( options.step )
\r
360 options.step.apply( elem, [ z.now ] );
\r
362 if ( prop == "opacity" )
\r
363 jQuery.attr(y, "opacity", z.now); // Let attr handle opacity
\r
364 else if ( parseInt(z.now) ) // My hate for IE will never die
\r
365 y[prop] = parseInt(z.now) + "px";
\r
368 // Figure out the maximum number to run to
\r
369 z.max = function(){
\r
370 return parseFloat( jQuery.css(elem,prop) );
\r
373 // Get the current size
\r
374 z.cur = function(){
\r
375 var r = parseFloat( jQuery.curCSS(elem, prop) );
\r
376 return r && r > -10000 ? r : z.max();
\r
379 // Start an animation from one number to another
\r
380 z.custom = function(from,to){
\r
381 z.startTime = (new Date()).getTime();
\r
385 z.timer = setInterval(function(){
\r
390 // Simple 'show' function
\r
391 z.show = function(){
\r
392 if ( !elem.orig ) elem.orig = {};
\r
394 // Remember where we started, so that we can go back to it later
\r
395 elem.orig[prop] = this.cur();
\r
397 options.show = true;
\r
399 // Begin the animation
\r
400 z.custom(0, elem.orig[prop]);
\r
402 // Stupid IE, look what you made me do
\r
403 if ( prop != "opacity" )
\r
407 // Simple 'hide' function
\r
408 z.hide = function(){
\r
409 if ( !elem.orig ) elem.orig = {};
\r
411 // Remember where we started, so that we can go back to it later
\r
412 elem.orig[prop] = this.cur();
\r
414 options.hide = true;
\r
416 // Begin the animation
\r
417 z.custom(elem.orig[prop], 0);
\r
420 //Simple 'toggle' function
\r
421 z.toggle = function() {
\r
422 if ( !elem.orig ) elem.orig = {};
\r
424 // Remember where we started, so that we can go back to it later
\r
425 elem.orig[prop] = this.cur();
\r
427 if(oldDisplay == 'none') {
\r
428 options.show = true;
\r
430 // Stupid IE, look what you made me do
\r
431 if ( prop != "opacity" )
\r
434 // Begin the animation
\r
435 z.custom(0, elem.orig[prop]);
\r
437 options.hide = true;
\r
439 // Begin the animation
\r
440 z.custom(elem.orig[prop], 0);
\r
444 // Each step of an animation
\r
445 z.step = function(firstNum, lastNum){
\r
446 var t = (new Date()).getTime();
\r
448 if (t > options.duration + z.startTime) {
\r
450 clearInterval(z.timer);
\r
456 if (elem.curAnim) elem.curAnim[ prop ] = true;
\r
459 for ( var i in elem.curAnim )
\r
460 if ( elem.curAnim[i] !== true )
\r
464 // Reset the overflow
\r
467 // Reset the display
\r
468 y.display = oldDisplay;
\r
469 if (jQuery.css(elem, 'display') == 'none')
\r
470 y.display = 'block';
\r
472 // Hide the element if the "hide" operation was done
\r
473 if ( options.hide )
\r
474 y.display = 'none';
\r
476 // Reset the properties, if the item has been hidden or shown
\r
477 if ( options.hide || options.show )
\r
478 for ( var p in elem.curAnim )
\r
479 if (p == "opacity")
\r
480 jQuery.attr(y, p, elem.orig[p]);
\r
485 // If a callback was provided, execute it
\r
486 if ( done && options.complete && options.complete.constructor == Function )
\r
487 // Execute the complete function
\r
488 options.complete.apply( elem );
\r
490 var n = t - this.startTime;
\r
491 // Figure out where in the animation we are and set the number
\r
492 var p = n / options.duration;
494 // If the easing function exists, then use it
\r
495 z.now = options.easing && jQuery.easing[options.easing] ?
496 jQuery.easing[options.easing](p, n, firstNum, (lastNum-firstNum), options.duration) :
497 // else use default linear easing
498 ((-Math.cos(p*Math.PI)/2) + 0.5) * (lastNum-firstNum) + firstNum;
\r
500 // Perform the next step of the animation
\r