Skip to content

Commit 0ae7802

Browse files
committed
Added a performance improvement to .hide()/.show() that helps to prevent constant reflows from occurring. Fixes jquery#4038.
1 parent 136a459 commit 0ae7802

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/fx.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ jQuery.fn.extend({
4444
elemdisplay[ tagName ] = display;
4545
}
4646

47-
this[i].style.display = jQuery.data(this[i], "olddisplay", display);
47+
jQuery.data(this[i], "olddisplay", display);
48+
}
49+
50+
// Set the display of the elements in a second loop
51+
// to avoid the constant reflow
52+
for ( var i = 0, l = this.length; i < l; i++ ){
53+
this[i].style.display = jQuery.data(this[i], "olddisplay");
4854
}
4955
}
5056

@@ -60,8 +66,14 @@ jQuery.fn.extend({
6066
var old = jQuery.data(this[i], "olddisplay");
6167
if ( !old && old !== "none" )
6268
jQuery.data(this[i], "olddisplay", jQuery.css(this[i], "display"));
69+
}
70+
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++ ){
6374
this[i].style.display = "none";
6475
}
76+
6577
return this;
6678
}
6779
},

0 commit comments

Comments
 (0)