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){
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 tagName = this[i].tagName, display;
33 if ( elemdisplay[ tagName ] ) {
34 display = elemdisplay[ tagName ];
36 var elem = jQuery("<" + tagName + " />").appendTo("body");
38 display = elem.css("display");
39 if ( display === "none" )
44 elemdisplay[ tagName ] = display;
47 this[i].style.display = jQuery.data(this[i], "olddisplay", display);
55 hide: function(speed,callback){
57 return this.animate( genFx("hide", 3), speed, callback);
59 for ( var i = 0, l = this.length; i < l; i++ ){
60 var old = jQuery.data(this[i], "olddisplay");
61 if ( !old && old !== "none" )
62 jQuery.data(this[i], "olddisplay", jQuery.css(this[i], "display"));
63 this[i].style.display = "none";
69 // Save the old toggle function
70 _toggle: jQuery.fn.toggle,
72 toggle: function( fn, fn2 ){
73 var bool = typeof fn === "boolean";
75 return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ?
76 this._toggle.apply( this, arguments ) :
79 var state = bool ? fn : jQuery(this).is(":hidden");
80 jQuery(this)[ state ? "show" : "hide" ]();
82 this.animate(genFx("toggle", 3), fn, fn2);
85 fadeTo: function(speed,to,callback){
86 return this.animate({opacity: to}, speed, callback);
89 animate: function( prop, speed, easing, callback ) {
90 var optall = jQuery.speed(speed, easing, callback);
92 return this[ optall.queue === false ? "each" : "queue" ](function(){
94 var opt = jQuery.extend({}, optall), p,
95 hidden = this.nodeType == 1 && jQuery(this).is(":hidden"),
99 if ( prop[p] == "hide" && hidden || prop[p] == "show" && !hidden )
100 return opt.complete.call(this);
102 if ( ( p == "height" || p == "width" ) && this.style ) {
103 // Store display property
104 opt.display = jQuery.css(this, "display");
106 // Make sure that nothing sneaks out
107 opt.overflow = this.style.overflow;
111 if ( opt.overflow != null )
112 this.style.overflow = "hidden";
114 opt.curAnim = jQuery.extend({}, prop);
116 jQuery.each( prop, function(name, val){
117 var e = new jQuery.fx( self, opt, name );
119 if ( /toggle|show|hide/.test(val) )
120 e[ val == "toggle" ? hidden ? "show" : "hide" : val ]( prop );
122 var parts = val.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),
123 start = e.cur(true) || 0;
126 var end = parseFloat(parts[2]),
127 unit = parts[3] || "px";
129 // We need to compute starting value
130 if ( unit != "px" ) {
131 self.style[ name ] = (end || 1) + unit;
132 start = ((end || 1) / e.cur(true)) * start;
133 self.style[ name ] = start + unit;
136 // If a +=/-= token was provided, we're doing a relative animation
138 end = ((parts[1] == "-=" ? -1 : 1) * end) + start;
140 e.custom( start, end, unit );
142 e.custom( start, val, "" );
146 // For JS strict compliance
151 stop: function(clearQueue, gotoEnd){
152 var timers = jQuery.timers;
157 this.each(function(){
158 // go in reverse order so anything added to the queue during the loop is ignored
159 for ( var i = timers.length - 1; i >= 0; i-- )
160 if ( timers[i].elem == this ) {
162 // force the next step to be the last
168 // start the next in the queue if the last step wasn't forced
177 // Generate shortcuts for custom animations
179 slideDown: genFx("show", 1),
180 slideUp: genFx("hide", 1),
181 slideToggle: genFx("toggle", 1),
182 fadeIn: { opacity: "show" },
183 fadeOut: { opacity: "hide" }
184 }, function( name, props ){
185 jQuery.fn[ name ] = function( speed, callback ){
186 return this.animate( props, speed, callback );
192 speed: function(speed, easing, fn) {
193 var opt = typeof speed === "object" ? speed : {
194 complete: fn || !fn && easing ||
195 jQuery.isFunction( speed ) && speed,
197 easing: fn && easing || easing && !jQuery.isFunction(easing) && easing
200 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
201 jQuery.fx.speeds[opt.duration] || jQuery.fx.speeds._default;
204 opt.old = opt.complete;
205 opt.complete = function(){
206 if ( opt.queue !== false )
207 jQuery(this).dequeue();
208 if ( jQuery.isFunction( opt.old ) )
209 opt.old.call( this );
216 linear: function( p, n, firstNum, diff ) {
217 return firstNum + diff * p;
219 swing: function( p, n, firstNum, diff ) {
220 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 if ( t() && jQuery.timers.push(t) == 1 ) {
277 timerId = setInterval(function(){
278 var timers = jQuery.timers;
280 for ( var i = 0; i < timers.length; i++ )
282 timers.splice(i--, 1);
284 if ( !timers.length ) {
285 clearInterval( timerId );
291 // Simple 'show' function
293 // Remember where we started, so that we can go back to it later
294 this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
295 this.options.show = true;
297 // Begin the animation
298 // Make sure that we start at a small width/height to avoid any
300 this.custom(this.prop == "width" || this.prop == "height" ? 1 : 0, this.cur());
302 // Start by showing the element
303 jQuery(this.elem).show();
306 // Simple 'hide' function
308 // Remember where we started, so that we can go back to it later
309 this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
310 this.options.hide = true;
312 // Begin the animation
313 this.custom(this.cur(), 0);
316 // Each step of an animation
317 step: function(gotoEnd){
320 if ( gotoEnd || t >= this.options.duration + this.startTime ) {
322 this.pos = this.state = 1;
325 this.options.curAnim[ this.prop ] = true;
328 for ( var i in this.options.curAnim )
329 if ( this.options.curAnim[i] !== true )
333 if ( this.options.display != null ) {
334 // Reset the overflow
335 this.elem.style.overflow = this.options.overflow;
338 this.elem.style.display = this.options.display;
339 if ( jQuery.css(this.elem, "display") == "none" )
340 this.elem.style.display = "block";
343 // Hide the element if the "hide" operation was done
344 if ( this.options.hide )
345 jQuery(this.elem).hide();
347 // Reset the properties, if the item has been hidden or shown
348 if ( this.options.hide || this.options.show )
349 for ( var p in this.options.curAnim )
350 jQuery.attr(this.elem.style, p, this.options.orig[p]);
352 // Execute the complete function
353 this.options.complete.call( this.elem );
358 var n = t - this.startTime;
359 this.state = n / this.options.duration;
361 // Perform the easing function, defaults to swing
362 this.pos = jQuery.easing[this.options.easing || (jQuery.easing.swing ? "swing" : "linear")](this.state, n, 0, 1, this.options.duration);
363 this.now = this.start + ((this.end - this.start) * this.pos);
365 // Perform the next step of the animation
374 jQuery.extend( jQuery.fx, {
383 opacity: function(fx){
384 jQuery.attr(fx.elem.style, "opacity", fx.now);
387 _default: function(fx){
388 if ( fx.elem.style && fx.elem.style[ fx.prop ] != null )
389 fx.elem.style[ fx.prop ] = fx.now + fx.unit;
391 fx.elem[ fx.prop ] = fx.now;