5 [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ],
7 [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
12 function genFx( type, num ){
14 jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function(){
21 show: function( speed, callback ) {
22 if ( speed != null ) {
23 return this.animate( genFx("show", 3), speed, callback);
25 for ( var i = 0, l = this.length; i < l; i++ ){
26 var old = jQuery.data(this[i], "olddisplay");
28 this[i].style.display = old || "";
30 if ( jQuery.css(this[i], "display") === "none" ) {
31 var nodeName = this[i].nodeName, display;
33 if ( elemdisplay[ nodeName ] ) {
34 display = elemdisplay[ nodeName ];
36 var elem = jQuery("<" + nodeName + " />").appendTo("body");
38 display = elem.css("display");
39 if ( display === "none" ) {
44 elemdisplay[ nodeName ] = display;
47 jQuery.data(this[i], "olddisplay", display);
51 // Set the display of the elements in a second loop
52 // to avoid the constant reflow
53 for ( var i = 0, l = this.length; i < l; i++ ){
54 this[i].style.display = jQuery.data(this[i], "olddisplay") || "";
61 hide: function( speed, callback ) {
62 if ( speed != null ) {
63 return this.animate( genFx("hide", 3), speed, callback);
65 for ( var i = 0, l = this.length; i < l; i++ ){
66 var old = jQuery.data(this[i], "olddisplay");
67 if ( !old && old !== "none" ){
68 jQuery.data(this[i], "olddisplay", jQuery.css(this[i], "display"));
72 // Set the display of the elements in a second loop
73 // to avoid the constant reflow
74 for ( var i = 0, l = this.length; i < l; i++ ){
75 this[i].style.display = "none";
82 // Save the old toggle function
83 _toggle: jQuery.fn.toggle,
85 toggle: function( fn, fn2 ){
86 var bool = typeof fn === "boolean";
88 return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ?
89 this._toggle.apply( this, arguments ) :
92 var state = bool ? fn : jQuery(this).is(":hidden");
93 jQuery(this)[ state ? "show" : "hide" ]();
95 this.animate(genFx("toggle", 3), fn, fn2);
98 fadeTo: function(speed,to,callback){
99 return this.filter(":hidden").css('opacity', 0).show().end()
100 .animate({opacity: to}, speed, callback);
103 animate: function( prop, speed, easing, callback ) {
104 var optall = jQuery.speed(speed, easing, callback);
106 return this[ optall.queue === false ? "each" : "queue" ](function(){
108 var opt = jQuery.extend({}, optall), p,
109 hidden = this.nodeType == 1 && jQuery(this).is(":hidden"),
113 var name = p.replace(rdashAlpha, fcamelCase);
116 prop[ name ] = prop[ p ];
121 if ( prop[p] == "hide" && hidden || prop[p] == "show" && !hidden ) {
122 return opt.complete.call(this);
124 if ( ( p == "height" || p == "width" ) && this.style ) {
125 // Store display property
126 opt.display = jQuery.css(this, "display");
128 // Make sure that nothing sneaks out
129 opt.overflow = this.style.overflow;
133 if ( opt.overflow != null ) {
134 this.style.overflow = "hidden";
136 opt.curAnim = jQuery.extend({}, prop);
138 jQuery.each( prop, function(name, val){
139 var e = new jQuery.fx( self, opt, name );
141 if ( /toggle|show|hide/.test(val) ) {
142 e[ val == "toggle" ? hidden ? "show" : "hide" : val ]( prop );
144 var parts = /^([+-]=)?([\d+-.]+)(.*)$/.exec(val),
145 start = e.cur(true) || 0;
148 var end = parseFloat(parts[2]),
149 unit = parts[3] || "px";
151 // We need to compute starting value
152 if ( unit != "px" ) {
153 self.style[ name ] = (end || 1) + unit;
154 start = ((end || 1) / e.cur(true)) * start;
155 self.style[ name ] = start + unit;
158 // If a +=/-= token was provided, we're doing a relative animation
160 end = ((parts[1] == "-=" ? -1 : 1) * end) + start;
162 e.custom( start, end, unit );
164 e.custom( start, val, "" );
169 if ( jQuery.isEmptyObject( prop ) ) {
170 return optall.complete.call(this);
173 // For JS strict compliance
178 stop: function(clearQueue, gotoEnd){
179 var timers = jQuery.timers;
184 this.each(function(){
185 // go in reverse order so anything added to the queue during the loop is ignored
186 for ( var i = timers.length - 1; i >= 0; i-- ) {
187 if ( timers[i].elem == this ) {
189 // force the next step to be the last
197 // start the next in the queue if the last step wasn't forced
206 // Generate shortcuts for custom animations
208 slideDown: genFx("show", 1),
209 slideUp: genFx("hide", 1),
210 slideToggle: genFx("toggle", 1),
211 fadeIn: { opacity: "show" },
212 fadeOut: { opacity: "hide" }
213 }, function( name, props ){
214 jQuery.fn[ name ] = function( speed, callback ){
215 return this.animate( props, speed, callback );
221 speed: function(speed, easing, fn) {
222 var opt = typeof speed === "object" ? speed : {
223 complete: fn || !fn && easing ||
224 jQuery.isFunction( speed ) && speed,
226 easing: fn && easing || easing && !jQuery.isFunction(easing) && easing
229 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
230 jQuery.fx.speeds[opt.duration] || jQuery.fx.speeds._default;
233 opt.old = opt.complete;
234 opt.complete = function(){
235 if ( opt.queue !== false ) {
236 jQuery(this).dequeue();
238 if ( jQuery.isFunction( opt.old ) ) {
239 opt.old.call( this );
247 linear: function( p, n, firstNum, diff ) {
248 return firstNum + diff * p;
250 swing: function( p, n, firstNum, diff ) {
251 return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
257 fx: function( elem, options, prop ){
258 this.options = options;
262 if ( !options.orig ) {
269 jQuery.fx.prototype = {
271 // Simple function for setting a style value
273 if ( this.options.step ) {
274 this.options.step.call( this.elem, this.now, this );
276 (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
278 // Set display property to block for height/width animations
279 if ( ( this.prop == "height" || this.prop == "width" ) && this.elem.style ) {
280 this.elem.style.display = "block";
284 // Get the current size
285 cur: function(force){
286 if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
287 return this.elem[ this.prop ];
289 var r = parseFloat(jQuery.css(this.elem, this.prop, force));
290 return r && r > -10000 ? r : parseFloat(jQuery.curCSS(this.elem, this.prop)) || 0;
293 // Start an animation from one number to another
294 custom: function(from, to, unit){
295 this.startTime = now();
298 this.unit = unit || this.unit || "px";
299 this.now = this.start;
300 this.pos = this.state = 0;
304 return self.step(gotoEnd);
309 if ( t() && jQuery.timers.push(t) && !timerId ) {
310 timerId = setInterval(jQuery.fx.tick, 13);
314 // Simple 'show' function
316 // Remember where we started, so that we can go back to it later
317 this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
318 this.options.show = true;
320 // Begin the animation
321 // Make sure that we start at a small width/height to avoid any
323 this.custom(this.prop == "width" || this.prop == "height" ? 1 : 0, this.cur());
325 // Start by showing the element
326 jQuery(this.elem).show();
329 // Simple 'hide' function
331 // Remember where we started, so that we can go back to it later
332 this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
333 this.options.hide = true;
335 // Begin the animation
336 this.custom(this.cur(), 0);
339 // Each step of an animation
340 step: function(gotoEnd){
343 if ( gotoEnd || t >= this.options.duration + this.startTime ) {
345 this.pos = this.state = 1;
348 this.options.curAnim[ this.prop ] = true;
351 for ( var i in this.options.curAnim ) {
352 if ( this.options.curAnim[i] !== true ) {
357 if ( this.options.display != null ) {
358 // Reset the overflow
359 this.elem.style.overflow = this.options.overflow;
362 this.elem.style.display = this.options.display;
363 if ( jQuery.css(this.elem, "display") == "none" ) {
364 this.elem.style.display = "block";
368 // Hide the element if the "hide" operation was done
369 if ( this.options.hide ) {
370 jQuery(this.elem).hide();
372 // Reset the properties, if the item has been hidden or shown
373 if ( this.options.hide || this.options.show ){
374 for ( var p in this.options.curAnim ) {
375 jQuery.style(this.elem, p, this.options.orig[p]);
378 // Execute the complete function
379 this.options.complete.call( this.elem );
384 var n = t - this.startTime;
385 this.state = n / this.options.duration;
387 // Perform the easing function, defaults to swing
388 this.pos = jQuery.easing[this.options.easing || (jQuery.easing.swing ? "swing" : "linear")](this.state, n, 0, 1, this.options.duration);
389 this.now = this.start + ((this.end - this.start) * this.pos);
391 // Perform the next step of the animation
400 jQuery.extend( jQuery.fx, {
403 var timers = jQuery.timers;
405 for ( var i = 0; i < timers.length; i++ ) {
406 if ( !timers[i]() ) {
407 timers.splice(i--, 1);
410 if ( !timers.length ) {
416 clearInterval( timerId );
429 opacity: function(fx){
430 jQuery.style(fx.elem, "opacity", fx.now);
433 _default: function(fx){
434 if ( fx.elem.style && fx.elem.style[ fx.prop ] != null ) {
435 fx.elem.style[ fx.prop ] = fx.now + fx.unit;
437 fx.elem[ fx.prop ] = fx.now;
443 if ( jQuery.expr && jQuery.expr.filters ) {
444 jQuery.expr.filters.animated = function(elem){
445 return jQuery.grep(jQuery.timers, function(fn){
446 return elem === fn.elem;