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
24 * @cat Effects/Animations
\r
25 * @see hide(String|Number,Function)
\r
27 show: function(speed,callback, easing){
\r
28 return speed ? this.animate({
\r
29 height: "show", width: "show", opacity: "show"
\r
30 }, speed, callback, easing) : 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
54 * @cat Effects/Animations
\r
55 * @see show(String|Number,Function)
\r
57 hide: function(speed,callback, easing){
\r
58 return speed ? this.animate({
\r
59 height: "hide", width: "hide", opacity: "hide"
\r
60 }, speed, callback, easing) : 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
81 * @cat Effects/Animations
\r
82 * @see slideUp(String|Number,Function)
\r
83 * @see slideToggle(String|Number,Function)
\r
85 slideDown: function(speed,callback, easing){
\r
86 return this.animate({height: "show"}, speed, callback, easing);
\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
107 * @cat Effects/Animations
\r
108 * @see slideDown(String|Number,Function)
\r
109 * @see slideToggle(String|Number,Function)
\r
111 slideUp: function(speed,callback, easing){
\r
112 return this.animate({height: "hide"}, speed, callback, easing);
\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
133 * @cat Effects/Animations
\r
134 * @see slideDown(String|Number,Function)
\r
135 * @see slideUp(String|Number,Function)
\r
137 slideToggle: function(speed, callback, easing){
\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, easing);
\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
163 * @cat Effects/Animations
\r
164 * @see fadeOut(String|Number,Function)
\r
165 * @see fadeTo(String|Number,Number,Function)
\r
167 fadeIn: function(speed, callback, easing){
\r
168 return this.animate({opacity: "show"}, speed, callback, easing);
\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
190 * @cat Effects/Animations
\r
191 * @see fadeIn(String|Number,Function)
\r
192 * @see fadeTo(String|Number,Number,Function)
\r
194 fadeOut: function(speed, callback, easing){
\r
195 return this.animate({opacity: "hide"}, speed, callback, easing);
\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
218 * @cat Effects/Animations
\r
219 * @see fadeIn(String|Number,Function)
\r
220 * @see fadeOut(String|Number,Function)
\r
222 fadeTo: function(speed,to,callback, easing){
\r
223 return this.animate({opacity: to}, speed, callback, easing);
\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
252 * @cat Effects/Animations
\r
254 animate: function(prop,speed,callback, easing) {
\r
255 return this.queue(function(){
\r
257 this.curAnim = jQuery.extend({}, prop);
\r
259 for ( var p in prop ) {
\r
260 var e = new jQuery.fx( this, jQuery.speed(speed,callback), p, easing );
\r
261 if ( prop[p].constructor == Number )
\r
262 e.custom( e.cur(), prop[p] );
\r
264 e[ prop[p] ]( prop );
\r
274 queue: function(type,fn){
\r
280 return this.each(function(){
\r
284 if ( !this.queue[type] )
\r
285 this.queue[type] = [];
\r
287 this.queue[type].push( fn );
\r
289 if ( this.queue[type].length == 1 )
\r
298 speed: function(s,o) {
\r
301 if ( o.constructor == Function )
\r
302 o = { complete: o };
\r
304 var ss = { slow: 600, fast: 200 };
\r
305 o.duration = (s && s.constructor == Number ? s : ss[s]) || 400;
\r
308 o.oldComplete = o.complete;
\r
309 o.complete = function(){
\r
310 jQuery.dequeue(this, "fx");
\r
311 if ( o.oldComplete && o.oldComplete.constructor == Function )
\r
312 o.oldComplete.apply( this );
\r
320 dequeue: function(elem,type){
\r
321 type = type || "fx";
\r
323 if ( elem.queue && elem.queue[type] ) {
\r
325 elem.queue[type].shift();
\r
327 // Get next function
\r
328 var f = elem.queue[type][0];
\r
330 if ( f ) f.apply( elem );
\r
335 * I originally wrote fx() as a clone of moo.fx and in the process
\r
336 * of making it small in size the code became illegible to sane
\r
337 * people. You've been warned.
\r
340 fx: function( elem, options, prop, easing ){
\r
344 // The users options
\r
346 duration: options.duration || 400,
\r
347 complete: options.complete,
\r
348 step: options.step,
\r
349 easing : easing || 'linear'
\r
356 var y = z.el.style;
\r
358 // Store display property
\r
359 var oldDisplay = jQuery.css(z.el, 'display');
\r
360 // Set display property to block for animation
\r
361 y.display = "block";
\r
362 // Make sure that nothing sneaks out
\r
363 y.overflow = "hidden";
\r
365 // Simple function for setting a style value
\r
367 if ( options.step )
\r
368 options.step.apply( elem, [ z.now ] );
\r
370 if ( prop == "opacity" )
\r
371 jQuery.attr(y, "opacity", z.now); // Let attr handle opacity
\r
372 else if ( parseInt(z.now) ) // My hate for IE will never die
\r
373 y[prop] = parseInt(z.now) + "px";
\r
376 // Figure out the maximum number to run to
\r
377 z.max = function(){
\r
378 return parseFloat( jQuery.css(z.el,prop) );
\r
381 // Get the current size
\r
382 z.cur = function(){
\r
383 var r = parseFloat( jQuery.curCSS(z.el, prop) );
\r
384 return r && r > -10000 ? r : z.max();
\r
387 // Start an animation from one number to another
\r
388 z.custom = function(from,to){
\r
389 z.startTime = (new Date()).getTime();
\r
393 z.timer = setInterval(function(){
\r
398 // Simple 'show' function
\r
399 z.show = function(){
\r
400 if ( !z.el.orig ) z.el.orig = {};
\r
402 // Remember where we started, so that we can go back to it later
\r
403 z.el.orig[prop] = this.cur();
\r
407 // Begin the animation
\r
408 z.custom(0, z.el.orig[prop]);
\r
410 // Stupid IE, look what you made me do
\r
411 if ( prop != "opacity" )
\r
415 // Simple 'hide' function
\r
416 z.hide = function(){
\r
417 if ( !z.el.orig ) z.el.orig = {};
\r
419 // Remember where we started, so that we can go back to it later
\r
420 z.el.orig[prop] = this.cur();
\r
424 // Begin the animation
\r
425 z.custom(z.el.orig[prop], 0);
\r
428 //Simple 'toggle' function
\r
429 z.toggle = function() {
\r
430 if ( !z.el.orig ) z.el.orig = {};
\r
432 // Remember where we started, so that we can go back to it later
\r
433 z.el.orig[prop] = this.cur();
\r
435 if(oldDisplay == 'none') {
\r
438 // Stupid IE, look what you made me do
\r
439 if ( prop != "opacity" )
\r
442 // Begin the animation
\r
443 z.custom(0, z.el.orig[prop]);
\r
447 // Begin the animation
\r
448 z.custom(z.el.orig[prop], 0);
\r
452 // Each step of an animation
\r
453 z.step = function(firstNum, lastNum){
\r
454 var t = (new Date()).getTime();
\r
456 if (t > z.o.duration + z.startTime) {
\r
458 clearInterval(z.timer);
\r
464 if (z.el.curAnim) z.el.curAnim[ prop ] = true;
\r
467 for ( var i in z.el.curAnim )
\r
468 if ( z.el.curAnim[i] !== true )
\r
472 // Reset the overflow
\r
475 // Reset the display
\r
476 y.display = oldDisplay;
\r
477 if (jQuery.css(z.el, 'display') == 'none')
\r
478 y.display = 'block';
\r
480 // Hide the element if the "hide" operation was done
\r
482 y.display = 'none';
\r
484 // Reset the properties, if the item has been hidden or shown
\r
485 if ( z.o.hide || z.o.show )
\r
486 for ( var p in z.el.curAnim )
\r
487 if (p == "opacity")
\r
488 jQuery.attr(y, p, z.el.orig[p]);
\r
493 // If a callback was provided, execute it
\r
494 if( done && z.o.complete && z.o.complete.constructor == Function )
\r
495 // Execute the complete function
\r
496 z.o.complete.apply( z.el );
\r
498 var n = t - this.startTime;
\r
499 // Figure out where in the animation we are and set the number
\r
500 var p = n / z.o.duration;
\r
501 //if the easing function exists then use it else use default linear easing
\r
502 if (jQuery.easing && jQuery.easing[z.o.easing])
\r
503 z.now = jQuery.easing[z.o.easing](p, n, firstNum, (lastNum-firstNum), z.o.duration);
\r
505 z.now = ((-Math.cos(p*Math.PI)/2) + 0.5) * (lastNum-firstNum) + firstNum;
\r
507 // Perform the next step of the animation
\r