3 // overwrite the old show method
7 * The effects module overloads the show method to now allow
8 * for a speed to the show operation. What actually happens is
9 * that the height, width, and opacity to the matched elements
10 * are changed dynamically. The only three current speeds are
11 * "slow", "normal", and "fast". For example:
12 * $("p").show("slow");
13 * Note: You should not run the show method on things
14 * that are already shown. This can be circumvented by doing this:
15 * $("p:hidden").show("slow");
17 show: function(speed,callback){
18 return speed ? this.animate({
19 height: "show", width: "show", opacity: "show"
20 }, speed, callback) : this._show();
23 // Overwrite the old hide method
24 _hide: jQuery.fn.hide,
27 * The hide function behaves very similary to the show function,
28 * but is just the opposite.
29 * $("p:visible").hide("slow");
31 hide: function(speed,callback){
32 return speed ? this.animate({
33 height: "hide", width: "hide", opacity: "hide"
34 }, speed, callback) : this._hide();
38 * This function increases the height and opacity for all matched
39 * elements. This is very similar to 'show', but does not change
40 * the width - creating a neat sliding effect.
41 * $("p:hidden").slideDown("slow");
43 slideDown: function(speed,callback){
44 return this.animate({height: "show"}, speed, callback);
48 * Just like slideDown, only it hides all matched elements.
49 * $("p:visible").slideUp("slow");
51 slideUp: function(speed,callback){
52 return this.animate({height: "hide"}, speed, callback);
56 * Adjusts the opacity of all matched elements from a hidden,
57 * to a fully visible, state.
58 * $("p:hidden").fadeIn("slow");
60 fadeIn: function(speed,callback){
61 return this.animate({opacity: "show"}, speed, callback);
65 * Same as fadeIn, but transitions from a visible, to a hidden state.
66 * $("p:visible").fadeOut("slow");
68 fadeOut: function(speed,callback){
69 return this.animate({opacity: "hide"}, speed, callback);
75 fadeTo: function(speed,to,callback){
76 return this.animate({opacity: to}, speed, callback);
82 animate: function(prop,speed,callback) {
83 return this.queue(function(){
85 for ( var p in prop ) {
86 var e = new jQuery.fx( this, jQuery.speed(speed,callback,i++), p );
87 if ( prop[p].constructor == Number )
88 e.custom( e.cur(), prop[p] );
99 queue: function(type,fn){
105 return this.each(function(){
109 if ( !this.queue[type] )
110 this.queue[type] = [];
112 this.queue[type].push( fn );
114 if ( this.queue[type].length == 1 )
123 setAuto: function(e,p) {
124 // Remember the original height
127 // Figure out the size of the height right now
128 var o = jQuery.curCSS(e,p,1);
130 // Set the height to auto
131 e.style[p] = e.currentStyle ? "" : "auto";
133 // See what the size of "auto" is
134 var n = jQuery.curCSS(e,p,1);
136 // Revert back to the original size
137 if ( o != n && n != "auto" ) e.style[p] = a;
140 speed: function(s,o,i) {
143 if ( o.constructor == Function )
146 var ss = { slow: 600, fast: 200 };
147 o.duration = (s && s.constructor == Number ? s : ss[s]) || 400;
150 o.oldComplete = o.complete;
151 o.complete = function(){
152 jQuery.dequeue(this, "fx");
153 if ( o.oldComplete && o.oldComplete.constructor == Function )
154 o.oldComplete.apply( this );
165 dequeue: function(elem,type){
168 if ( elem.queue && elem.queue[type] ) {
170 elem.queue[type].shift();
173 var f = elem.queue[type][0];
181 * I originally wrote fx() as a clone of moo.fx and in the process
182 * of making it small in size the code became illegible to sane
183 * people. You've been warned.
186 fx: function( elem, options, prop ){
192 duration: options.duration || 400,
193 complete: options.complete
202 // Simple function for setting a style value
204 if ( prop == "opacity" ) {
205 if (z.now == 1) z.now = 0.9999;
206 if (window.ActiveXObject)
207 y.filter = "alpha(opacity=" + z.now*100 + ")";
210 // My hate for IE will never die
211 } else if ( parseInt(z.now) )
212 y[prop] = parseInt(z.now) + "px";
215 // Figure out the maximum number to run to
217 return parseFloat( jQuery.css(z.el,prop) );
220 // Get the current size
222 return parseFloat( jQuery.curCSS(z.el,prop) ) || z.max();
225 // Start an animation from one number to another
226 z.custom = function(from,to){
227 z.startTime = (new Date()).getTime();
231 z.timer = setInterval(function(){
236 // Simple 'show' function
238 if ( !z.el.orig ) z.el.orig = {};
240 // Remember where we started, so that we can go back to it later
241 z.el.orig[prop] = this.cur();
243 if ( !y[prop] ) z.o.auto = true;
247 // Stupid IE, look what you made me do
248 if ( prop != "opacity" )
254 // Simple 'hide' function
256 if ( !z.el.orig ) z.el.orig = {};
258 // Remember where we started, so that we can go back to it later
259 z.el.orig[prop] = this.cur();
263 // Begin the animation
267 // IE has trouble with opacity if it does not have layout
268 if ( jQuery.browser.msie && !z.el.currentStyle.hasLayout )
271 // Remember the overflow of the element
272 z.oldOverflow = y.overflow;
274 // Make sure that nothing sneaks out
275 y.overflow = "hidden";
277 // Each step of an animation
278 z.step = function(firstNum, lastNum){
279 var t = (new Date()).getTime();
281 if (t > z.o.duration + z.startTime) {
283 clearInterval(z.timer);
289 // Hide the element if the "hide" operation was done
290 if ( z.o.hide ) y.display = 'none';
292 // Reset the overflow
293 y.overflow = z.oldOverflow;
295 // If a callback was provided, execute it
296 if( z.o.complete && z.o.complete.constructor == Function )
297 // Execute the complete function
298 z.o.complete.apply( z.el );
300 // Reset the property, if the item has been hidden
302 y[ prop ] = z.el.orig[ prop ].constructor == Number && prop != "opacity" ? z.el.orig[prop] + "px" : z.el.orig[prop];
304 // set its height and/or width to auto
305 jQuery.setAuto( z.el, prop );
307 // Figure out where in the animation we are and set the number
308 var p = (t - this.startTime) / z.o.duration;
309 z.now = ((-Math.cos(p*Math.PI)/2) + 0.5) * (lastNum-firstNum) + firstNum;
311 // Perform the next step of the animation