4 [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ],
6 [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
11 function genFx( type, num ){
13 jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function(){
20 show: function(speed,callback){
22 return this.animate( genFx("show", 3), speed, callback);
24 for ( var i = 0, l = this.length; i < l; i++ ){
25 var old = jQuery.data(this[i], "olddisplay");
27 this[i].style.display = old || "";
29 if ( jQuery.css(this[i], "display") === "none" ) {
30 var tagName = this[i].tagName, display;
32 if ( elemdisplay[ tagName ] ) {
33 display = elemdisplay[ tagName ];
35 var elem = jQuery("<" + tagName + " />").appendTo("body");
37 display = elem.css("display");
38 if ( display === "none" )
43 elemdisplay[ tagName ] = display;
46 this[i].style.display = jQuery.data(this[i], "olddisplay", display);
54 hide: function(speed,callback){
56 return this.animate( genFx("hide", 3), speed, callback);
58 for ( var i = 0, l = this.length; i < l; i++ ){
59 var old = jQuery.data(this[i], "olddisplay");
60 if ( !old && old !== "none" )
61 jQuery.data(this[i], "olddisplay", jQuery.css(this[i], "display"));
62 this[i].style.display = "none";
68 // Save the old toggle function
69 _toggle: jQuery.fn.toggle,
71 toggle: function( fn, fn2 ){
72 var bool = typeof fn === "boolean";
74 return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ?
75 this._toggle.apply( this, arguments ) :
78 var state = bool ? fn : jQuery(this).is(":hidden");
79 jQuery(this)[ state ? "show" : "hide" ]();
81 this.animate(genFx("toggle", 3), fn, fn2);
84 fadeTo: function(speed,to,callback){
85 return this.animate({opacity: to}, speed, callback);
88 animate: function( prop, speed, easing, callback ) {
89 var optall = jQuery.speed(speed, easing, callback);
91 return this[ optall.queue === false ? "each" : "queue" ](function(){
93 var opt = jQuery.extend({}, optall), p,
94 hidden = this.nodeType == 1 && jQuery(this).is(":hidden"),
98 if ( prop[p] == "hide" && hidden || prop[p] == "show" && !hidden )
99 return opt.complete.call(this);
101 if ( ( p == "height" || p == "width" ) && this.style ) {
102 // Store display property
103 opt.display = jQuery.css(this, "display");
105 // Make sure that nothing sneaks out
106 opt.overflow = this.style.overflow;
110 if ( opt.overflow != null )
111 this.style.overflow = "hidden";
113 opt.curAnim = jQuery.extend({}, prop);
115 jQuery.each( prop, function(name, val){
116 var e = new jQuery.fx( self, opt, name );
118 if ( /toggle|show|hide/.test(val) )
119 e[ val == "toggle" ? hidden ? "show" : "hide" : val ]( prop );
121 var parts = val.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),
122 start = e.cur(true) || 0;
125 var end = parseFloat(parts[2]),
126 unit = parts[3] || "px";
128 // We need to compute starting value
129 if ( unit != "px" ) {
130 self.style[ name ] = (end || 1) + unit;
131 start = ((end || 1) / e.cur(true)) * start;
132 self.style[ name ] = start + unit;
135 // If a +=/-= token was provided, we're doing a relative animation
137 end = ((parts[1] == "-=" ? -1 : 1) * end) + start;
139 e.custom( start, end, unit );
141 e.custom( start, val, "" );
145 // For JS strict compliance
150 stop: function(clearQueue, gotoEnd){
151 var timers = jQuery.timers;
156 this.each(function(){
157 // go in reverse order so anything added to the queue during the loop is ignored
158 for ( var i = timers.length - 1; i >= 0; i-- )
159 if ( timers[i].elem == this ) {
161 // force the next step to be the last
167 // start the next in the queue if the last step wasn't forced
176 // Generate shortcuts for custom animations
178 slideDown: genFx("show", 1),
179 slideUp: genFx("hide", 1),
180 slideToggle: genFx("toggle", 1),
181 fadeIn: { opacity: "show" },
182 fadeOut: { opacity: "hide" }
183 }, function( name, props ){
184 jQuery.fn[ name ] = function( speed, callback ){
185 return this.animate( props, speed, callback );
191 speed: function(speed, easing, fn) {
192 var opt = typeof speed === "object" ? speed : {
193 complete: fn || !fn && easing ||
194 jQuery.isFunction( speed ) && speed,
196 easing: fn && easing || easing && !jQuery.isFunction(easing) && easing
199 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
200 jQuery.fx.speeds[opt.duration] || jQuery.fx.speeds._default;
203 opt.old = opt.complete;
204 opt.complete = function(){
205 if ( opt.queue !== false )
206 jQuery(this).dequeue();
207 if ( jQuery.isFunction( opt.old ) )
208 opt.old.call( this );
215 linear: function( p, n, firstNum, diff ) {
216 return firstNum + diff * p;
218 swing: function( p, n, firstNum, diff ) {
219 return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
226 fx: function( elem, options, prop ){
227 this.options = options;
237 jQuery.fx.prototype = {
239 // Simple function for setting a style value
241 if ( this.options.step )
242 this.options.step.call( this.elem, this.now, this );
244 (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
246 // Set display property to block for height/width animations
247 if ( ( this.prop == "height" || this.prop == "width" ) && this.elem.style )
248 this.elem.style.display = "block";
251 // Get the current size
252 cur: function(force){
253 if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) )
254 return this.elem[ this.prop ];
256 var r = parseFloat(jQuery.css(this.elem, this.prop, force));
257 return r && r > -10000 ? r : parseFloat(jQuery.curCSS(this.elem, this.prop)) || 0;
260 // Start an animation from one number to another
261 custom: function(from, to, unit){
262 this.startTime = now();
265 this.unit = unit || this.unit || "px";
266 this.now = this.start;
267 this.pos = this.state = 0;
271 return self.step(gotoEnd);
276 jQuery.timers.push(t);
278 if ( t() && jQuery.timerId == null ) {
279 jQuery.timerId = setInterval(function(){
280 var timers = jQuery.timers;
282 for ( var i = 0; i < timers.length; i++ )
284 timers.splice(i--, 1);
286 if ( !timers.length ) {
287 clearInterval( jQuery.timerId );
288 jQuery.timerId = null;
294 // Simple 'show' function
296 // Remember where we started, so that we can go back to it later
297 this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
298 this.options.show = true;
300 // Begin the animation
301 // Make sure that we start at a small width/height to avoid any
303 this.custom(this.prop == "width" || this.prop == "height" ? 1 : 0, this.cur());
305 // Start by showing the element
306 jQuery(this.elem).show();
309 // Simple 'hide' function
311 // Remember where we started, so that we can go back to it later
312 this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
313 this.options.hide = true;
315 // Begin the animation
316 this.custom(this.cur(), 0);
319 // Each step of an animation
320 step: function(gotoEnd){
323 if ( gotoEnd || t >= this.options.duration + this.startTime ) {
325 this.pos = this.state = 1;
328 this.options.curAnim[ this.prop ] = true;
331 for ( var i in this.options.curAnim )
332 if ( this.options.curAnim[i] !== true )
336 if ( this.options.display != null ) {
337 // Reset the overflow
338 this.elem.style.overflow = this.options.overflow;
341 this.elem.style.display = this.options.display;
342 if ( jQuery.css(this.elem, "display") == "none" )
343 this.elem.style.display = "block";
346 // Hide the element if the "hide" operation was done
347 if ( this.options.hide )
348 jQuery(this.elem).hide();
350 // Reset the properties, if the item has been hidden or shown
351 if ( this.options.hide || this.options.show )
352 for ( var p in this.options.curAnim )
353 jQuery.attr(this.elem.style, p, this.options.orig[p]);
357 // Execute the complete function
358 this.options.complete.call( this.elem );
362 var n = t - this.startTime;
363 this.state = n / this.options.duration;
365 // Perform the easing function, defaults to swing
366 this.pos = jQuery.easing[this.options.easing || (jQuery.easing.swing ? "swing" : "linear")](this.state, n, 0, 1, this.options.duration);
367 this.now = this.start + ((this.end - this.start) * this.pos);
369 // Perform the next step of the animation
378 jQuery.extend( jQuery.fx, {
387 opacity: function(fx){
388 jQuery.attr(fx.elem.style, "opacity", fx.now);
391 _default: function(fx){
392 if ( fx.elem.style && fx.elem.style[ fx.prop ] != null )
393 fx.elem.style[ fx.prop ] = fx.now + fx.unit;
395 fx.elem[ fx.prop ] = fx.now;