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 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){
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"));
71 // Set the display of the elements in a second loop
72 // to avoid the constant reflow
73 for ( var i = 0, l = this.length; i < l; i++ ){
74 this[i].style.display = "none";
81 // Save the old toggle function
82 _toggle: jQuery.fn.toggle,
84 toggle: function( fn, fn2 ){
85 var bool = typeof fn === "boolean";
87 return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ?
88 this._toggle.apply( this, arguments ) :
91 var state = bool ? fn : jQuery(this).is(":hidden");
92 jQuery(this)[ state ? "show" : "hide" ]();
94 this.animate(genFx("toggle", 3), fn, fn2);
97 fadeTo: function(speed,to,callback){
98 return this.filter(":hidden").css('opacity', 0).show().end()
99 .animate({opacity: to}, speed, callback);
102 animate: function( prop, speed, easing, callback ) {
103 var optall = jQuery.speed(speed, easing, callback);
105 return this[ optall.queue === false ? "each" : "queue" ](function(){
107 var opt = jQuery.extend({}, optall), p,
108 hidden = this.nodeType == 1 && jQuery(this).is(":hidden"),
112 if ( prop[p] == "hide" && hidden || prop[p] == "show" && !hidden )
113 return opt.complete.call(this);
115 if ( ( p == "height" || p == "width" ) && this.style ) {
116 // Store display property
117 opt.display = jQuery.css(this, "display");
119 // Make sure that nothing sneaks out
120 opt.overflow = this.style.overflow;
124 if ( opt.overflow != null )
125 this.style.overflow = "hidden";
127 opt.curAnim = jQuery.extend({}, prop);
129 jQuery.each( prop, function(name, val){
130 var e = new jQuery.fx( self, opt, name );
132 if ( /toggle|show|hide/.test(val) )
133 e[ val == "toggle" ? hidden ? "show" : "hide" : val ]( prop );
135 var parts = val.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),
136 start = e.cur(true) || 0;
139 var end = parseFloat(parts[2]),
140 unit = parts[3] || "px";
142 // We need to compute starting value
143 if ( unit != "px" ) {
144 self.style[ name ] = (end || 1) + unit;
145 start = ((end || 1) / e.cur(true)) * start;
146 self.style[ name ] = start + unit;
149 // If a +=/-= token was provided, we're doing a relative animation
151 end = ((parts[1] == "-=" ? -1 : 1) * end) + start;
153 e.custom( start, end, unit );
155 e.custom( start, val, "" );
159 // For JS strict compliance
164 stop: function(clearQueue, gotoEnd){
165 var timers = jQuery.timers;
170 this.each(function(){
171 // go in reverse order so anything added to the queue during the loop is ignored
172 for ( var i = timers.length - 1; i >= 0; i-- )
173 if ( timers[i].elem == this ) {
175 // force the next step to be the last
181 // start the next in the queue if the last step wasn't forced
190 // Generate shortcuts for custom animations
192 slideDown: genFx("show", 1),
193 slideUp: genFx("hide", 1),
194 slideToggle: genFx("toggle", 1),
195 fadeIn: { opacity: "show" },
196 fadeOut: { opacity: "hide" }
197 }, function( name, props ){
198 jQuery.fn[ name ] = function( speed, callback ){
199 return this.animate( props, speed, callback );
205 speed: function(speed, easing, fn) {
206 var opt = typeof speed === "object" ? speed : {
207 complete: fn || !fn && easing ||
208 jQuery.isFunction( speed ) && speed,
210 easing: fn && easing || easing && !jQuery.isFunction(easing) && easing
213 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
214 jQuery.fx.speeds[opt.duration] || jQuery.fx.speeds._default;
217 opt.old = opt.complete;
218 opt.complete = function(){
219 if ( opt.queue !== false )
220 jQuery(this).dequeue();
221 if ( jQuery.isFunction( opt.old ) )
222 opt.old.call( this );
229 linear: function( p, n, firstNum, diff ) {
230 return firstNum + diff * p;
232 swing: function( p, n, firstNum, diff ) {
233 return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
239 fx: function( elem, options, prop ){
240 this.options = options;
250 jQuery.fx.prototype = {
252 // Simple function for setting a style value
254 if ( this.options.step )
255 this.options.step.call( this.elem, this.now, this );
257 (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
259 // Set display property to block for height/width animations
260 if ( ( this.prop == "height" || this.prop == "width" ) && this.elem.style )
261 this.elem.style.display = "block";
264 // Get the current size
265 cur: function(force){
266 if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) )
267 return this.elem[ this.prop ];
269 var r = parseFloat(jQuery.css(this.elem, this.prop, force));
270 return r && r > -10000 ? r : parseFloat(jQuery.curCSS(this.elem, this.prop)) || 0;
273 // Start an animation from one number to another
274 custom: function(from, to, unit){
275 this.startTime = now();
278 this.unit = unit || this.unit || "px";
279 this.now = this.start;
280 this.pos = this.state = 0;
284 return self.step(gotoEnd);
289 if ( t() && jQuery.timers.push(t) && !timerId ) {
290 timerId = setInterval(function(){
291 var timers = jQuery.timers;
293 for ( var i = 0; i < timers.length; i++ )
295 timers.splice(i--, 1);
297 if ( !timers.length ) {
298 clearInterval( timerId );
305 // Simple 'show' function
307 // Remember where we started, so that we can go back to it later
308 this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
309 this.options.show = true;
311 // Begin the animation
312 // Make sure that we start at a small width/height to avoid any
314 this.custom(this.prop == "width" || this.prop == "height" ? 1 : 0, this.cur());
316 // Start by showing the element
317 jQuery(this.elem).show();
320 // Simple 'hide' function
322 // Remember where we started, so that we can go back to it later
323 this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
324 this.options.hide = true;
326 // Begin the animation
327 this.custom(this.cur(), 0);
330 // Each step of an animation
331 step: function(gotoEnd){
334 if ( gotoEnd || t >= this.options.duration + this.startTime ) {
336 this.pos = this.state = 1;
339 this.options.curAnim[ this.prop ] = true;
342 for ( var i in this.options.curAnim )
343 if ( this.options.curAnim[i] !== true )
347 if ( this.options.display != null ) {
348 // Reset the overflow
349 this.elem.style.overflow = this.options.overflow;
352 this.elem.style.display = this.options.display;
353 if ( jQuery.css(this.elem, "display") == "none" )
354 this.elem.style.display = "block";
357 // Hide the element if the "hide" operation was done
358 if ( this.options.hide )
359 jQuery(this.elem).hide();
361 // Reset the properties, if the item has been hidden or shown
362 if ( this.options.hide || this.options.show )
363 for ( var p in this.options.curAnim )
364 jQuery.style(this.elem, p, this.options.orig[p]);
366 // Execute the complete function
367 this.options.complete.call( this.elem );
372 var n = t - this.startTime;
373 this.state = n / this.options.duration;
375 // Perform the easing function, defaults to swing
376 this.pos = jQuery.easing[this.options.easing || (jQuery.easing.swing ? "swing" : "linear")](this.state, n, 0, 1, this.options.duration);
377 this.now = this.start + ((this.end - this.start) * this.pos);
379 // Perform the next step of the animation
388 jQuery.extend( jQuery.fx, {
397 opacity: function(fx){
398 jQuery.style(fx.elem, "opacity", fx.now);
401 _default: function(fx){
402 if ( fx.elem.style && fx.elem.style[ fx.prop ] != null )
403 fx.elem.style[ fx.prop ] = fx.now + fx.unit;
405 fx.elem[ fx.prop ] = fx.now;