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 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
77 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
78 * @cat Effects/Animations
\r
80 slideDown: function(speed,callback){
\r
81 return this.animate({height: "show"}, speed, callback);
\r
85 * Hide all matched elements by adjusting their height and firing an
\r
86 * optional callback after completion.
\r
88 * Only the height is adjusted for this animation, causing all matched
\r
89 * elements to be hidden in a "sliding" manner.
\r
91 * @example $("p").slideUp("slow");
\r
93 * @example $("p").slideUp("slow",function(){
\r
94 * alert("Animation Done.");
\r
99 * @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
100 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
101 * @cat Effects/Animations
\r
103 slideUp: function(speed,callback){
\r
104 return this.animate({height: "hide"}, speed, callback);
\r
108 * Toggle the visibility of all matched elements by adjusting their height and firing an
\r
109 * optional callback after completion.
\r
111 * Only the height is adjusted for this animation, causing all matched
\r
112 * elements to be hidden in a "sliding" manner.
\r
114 * @example $("p").slideToggle("slow");
\r
116 * @example $("p").slideToggle("slow",function(){
\r
117 * alert("Animation Done.");
\r
120 * @name slideToggle
\r
122 * @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
123 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
124 * @cat Effects/Animations
\r
126 slideToggle: function(speed,callback){
\r
127 return this.each(function(){
\r
128 var state = jQuery(this).is(":hidden") ? "show" : "hide";
\r
129 jQuery(this).animate({height: state}, speed, callback);
\r
134 * Fade in all matched elements by adjusting their opacity and firing an
\r
135 * optional callback after completion.
\r
137 * Only the opacity is adjusted for this animation, meaning that
\r
138 * all of the matched elements should already have some form of height
\r
139 * and width associated with them.
\r
141 * @example $("p").fadeIn("slow");
\r
143 * @example $("p").fadeIn("slow",function(){
\r
144 * alert("Animation Done.");
\r
149 * @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
150 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
151 * @cat Effects/Animations
\r
153 fadeIn: function(speed,callback){
\r
154 return this.animate({opacity: "show"}, speed, callback);
\r
158 * Fade out all matched elements by adjusting their opacity and firing an
\r
159 * optional callback after completion.
\r
161 * Only the opacity is adjusted for this animation, meaning that
\r
162 * all of the matched elements should already have some form of height
\r
163 * and width associated with them.
\r
165 * @example $("p").fadeOut("slow");
\r
167 * @example $("p").fadeOut("slow",function(){
\r
168 * alert("Animation Done.");
\r
173 * @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
174 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
175 * @cat Effects/Animations
\r
177 fadeOut: function(speed,callback){
\r
178 return this.animate({opacity: "hide"}, speed, callback);
\r
182 * Fade the opacity of all matched elements to a specified opacity and firing an
\r
183 * optional callback after completion.
\r
185 * Only the opacity is adjusted for this animation, meaning that
\r
186 * all of the matched elements should already have some form of height
\r
187 * and width associated with them.
\r
189 * @example $("p").fadeTo("slow", 0.5);
\r
191 * @example $("p").fadeTo("slow", 0.5, function(){
\r
192 * alert("Animation Done.");
\r
197 * @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
198 * @param Number opacity The opacity to fade to (a number from 0 to 1).
\r
199 * @param Function callback (optional) A function to be executed whenever the animation completes.
\r
200 * @cat Effects/Animations
\r
202 fadeTo: function(speed,to,callback){
\r
203 return this.animate({opacity: to}, speed, callback);
\r
207 * A function for making your own, custom, animations. The key aspect of
\r
208 * this function is the object of style properties that will be animated,
\r
209 * and to what end. Each key within the object represents a style property
\r
210 * that will also be animated (for example: "height", "top", or "opacity").
\r
212 * The value associated with the key represents to what end the property
\r
213 * will be animated. If a number is provided as the value, then the style
\r
214 * property will be transitioned from its current state to that new number.
\r
215 * Oterwise if the string "hide", "show", or "toggle" is provided, a default
\r
216 * animation will be constructed for that property.
\r
218 * @example $("p").animate({
\r
219 * height: 'toggle', opacity: 'toggle'
\r
222 * @example $("p").animate({
\r
223 * left: 50, opacity: 'show'
\r
228 * @param Hash params A set of style attributes that you wish to animate, and to what end.
\r
229 * @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
230 * @param Function callback A function to be executed whenever the animation completes.
\r
231 * @cat Effects/Animations
\r
233 animate: function(prop,speed,callback) {
\r
234 return this.queue(function(){
\r
236 this.curAnim = jQuery.extend({}, prop);
\r
238 for ( var p in prop ) {
\r
239 var e = new jQuery.fx( this, jQuery.speed(speed,callback), p );
\r
240 if ( prop[p].constructor == Number )
\r
241 e.custom( e.cur(), prop[p] );
\r
243 e[ prop[p] ]( prop );
\r
253 queue: function(type,fn){
\r
259 return this.each(function(){
\r
263 if ( !this.queue[type] )
\r
264 this.queue[type] = [];
\r
266 this.queue[type].push( fn );
\r
268 if ( this.queue[type].length == 1 )
\r
277 speed: function(s,o) {
\r
280 if ( o.constructor == Function )
\r
281 o = { complete: o };
\r
283 var ss = { slow: 600, fast: 200 };
\r
284 o.duration = (s && s.constructor == Number ? s : ss[s]) || 400;
\r
287 o.oldComplete = o.complete;
\r
288 o.complete = function(){
\r
289 jQuery.dequeue(this, "fx");
\r
290 if ( o.oldComplete && o.oldComplete.constructor == Function )
\r
291 o.oldComplete.apply( this );
\r
299 dequeue: function(elem,type){
\r
300 type = type || "fx";
\r
302 if ( elem.queue && elem.queue[type] ) {
\r
304 elem.queue[type].shift();
\r
306 // Get next function
\r
307 var f = elem.queue[type][0];
\r
309 if ( f ) f.apply( elem );
\r
314 * I originally wrote fx() as a clone of moo.fx and in the process
\r
315 * of making it small in size the code became illegible to sane
\r
316 * people. You've been warned.
\r
319 fx: function( elem, options, prop ){
\r
323 // The users options
\r
325 duration: options.duration || 400,
\r
326 complete: options.complete,
\r
334 var y = z.el.style;
\r
336 // Store display property
\r
337 var oldDisplay = jQuery.css(z.el, 'display');
\r
338 // Set display property to block for animation
\r
339 y.display = "block";
\r
340 // Make sure that nothing sneaks out
\r
341 y.overflow = "hidden";
\r
343 // Simple function for setting a style value
\r
345 if ( options.step )
\r
346 options.step.apply( elem, [ z.now ] );
\r
348 if ( prop == "opacity" )
\r
349 jQuery.attr(y, "opacity", z.now); // Let attr handle opacity
\r
350 else if ( parseInt(z.now) ) // My hate for IE will never die
\r
351 y[prop] = parseInt(z.now) + "px";
\r
354 // Figure out the maximum number to run to
\r
355 z.max = function(){
\r
356 return parseFloat( jQuery.css(z.el,prop) );
\r
359 // Get the current size
\r
360 z.cur = function(){
\r
361 var r = parseFloat( jQuery.curCSS(z.el, prop) );
\r
362 return r && r > -10000 ? r : z.max();
\r
365 // Start an animation from one number to another
\r
366 z.custom = function(from,to){
\r
367 z.startTime = (new Date()).getTime();
\r
371 z.timer = setInterval(function(){
\r
376 // Simple 'show' function
\r
377 z.show = function(){
\r
378 if ( !z.el.orig ) z.el.orig = {};
\r
380 // Remember where we started, so that we can go back to it later
\r
381 z.el.orig[prop] = this.cur();
\r
385 // Begin the animation
\r
386 z.custom(0, z.el.orig[prop]);
\r
388 // Stupid IE, look what you made me do
\r
389 if ( prop != "opacity" )
\r
393 // Simple 'hide' function
\r
394 z.hide = function(){
\r
395 if ( !z.el.orig ) z.el.orig = {};
\r
397 // Remember where we started, so that we can go back to it later
\r
398 z.el.orig[prop] = this.cur();
\r
402 // Begin the animation
\r
403 z.custom(z.el.orig[prop], 0);
\r
406 //Simple 'toggle' function
\r
407 z.toggle = function() {
\r
408 if ( !z.el.orig ) z.el.orig = {};
\r
410 // Remember where we started, so that we can go back to it later
\r
411 z.el.orig[prop] = this.cur();
\r
413 if(oldDisplay == 'none') {
\r
416 // Stupid IE, look what you made me do
\r
417 if ( prop != "opacity" )
\r
420 // Begin the animation
\r
421 z.custom(0, z.el.orig[prop]);
\r
425 // Begin the animation
\r
426 z.custom(z.el.orig[prop], 0);
\r
430 // Each step of an animation
\r
431 z.step = function(firstNum, lastNum){
\r
432 var t = (new Date()).getTime();
\r
434 if (t > z.o.duration + z.startTime) {
\r
436 clearInterval(z.timer);
\r
442 if (z.el.curAnim) z.el.curAnim[ prop ] = true;
\r
445 for ( var i in z.el.curAnim )
\r
446 if ( z.el.curAnim[i] !== true )
\r
450 // Reset the overflow
\r
453 // Reset the display
\r
454 y.display = oldDisplay;
\r
455 if (jQuery.css(z.el, 'display') == 'none')
\r
456 y.display = 'block';
\r
458 // Hide the element if the "hide" operation was done
\r
460 y.display = 'none';
\r
462 // Reset the properties, if the item has been hidden or shown
\r
463 if ( z.o.hide || z.o.show )
\r
464 for ( var p in z.el.curAnim )
\r
465 if (p == "opacity")
\r
466 jQuery.attr(y, p, z.el.orig[p]);
\r
471 // If a callback was provided, execute it
\r
472 if( done && z.o.complete && z.o.complete.constructor == Function )
\r
473 // Execute the complete function
\r
474 z.o.complete.apply( z.el );
\r
476 // Figure out where in the animation we are and set the number
\r
477 var p = (t - this.startTime) / z.o.duration;
\r
478 z.now = ((-Math.cos(p*Math.PI)/2) + 0.5) * (lastNum-firstNum) + firstNum;
\r
480 // Perform the next step of the animation
\r