It is this line that causes flickering. I wrote this extension to remove a line from the show function. Note that it always sets the display element to "block".
In the end, I decided it differently. I used the span element and changed it to a div.
/** fixes flicker in jQuery show function */ var fxAttrs = [ // height animations [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ], // width animations [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ], // opacity animations [ "opacity" ] ]; function genFx( type, num ){ var obj = {}; jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function(){ obj[ this ] = type; }); return obj; } (function($){ $.fn.extend({ show: function(speed,callback){ if ( speed ) { return this.animate(genFx("show", 3), speed, callback); } else { for ( var i = 0, l = this.length; i < l; i++ ){ var old = jQuery.data(this[i], "olddisplay"); this[i].style.display = old || ""; if ( jQuery.css(this[i], "display") === "none" ) { jQuery.data(this[i], "olddisplay", 'block'); } } // Set the display of the elements in a second loop // to avoid the constant reflow for ( var i = 0, l = this.length; i < l; i++ ){ this[i].style.display = jQuery.data(this[i], "olddisplay") || ""; } return this; } } }); })(jQuery);
source share