Skip to content
Permalink
Browse files

Added a performance improvement to .hide()/.show() that helps to prev…

…ent constant reflows from occurring. Fixes #4038.
  • Loading branch information
jeresig committed Feb 9, 2009
1 parent 136a459 commit 0ae78024c23dd3ef4bcea883338d975dcf843597
Showing with 13 additions and 1 deletion.
  1. +13 −1 src/fx.js
@@ -44,7 +44,13 @@ jQuery.fn.extend({
elemdisplay[ tagName ] = display;
}

this[i].style.display = jQuery.data(this[i], "olddisplay", display);
jQuery.data(this[i], "olddisplay", display);
}

// 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");
}
}

@@ -60,8 +66,14 @@ jQuery.fn.extend({
var old = jQuery.data(this[i], "olddisplay");
if ( !old && old !== "none" )
jQuery.data(this[i], "olddisplay", jQuery.css(this[i], "display"));
}

// 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 = "none";
}

return this;
}
},

0 comments on commit 0ae7802

Please sign in to comment.
You can’t perform that action at this time.