When making a number of style changes that trigger reflow, is it better to hide the element before making the changes, and then show it again after the changes are complete?
Preparation code
<divid="my-wrapper"></div> <script> var myWrapper = document.getElementById('my-wrapper'); </script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
Testing in unknown unknown
Test
Ops/sec
Separate Reflows
// first add the list, for testing purposes myWrapper.innerHTML='<ul id="my-list"><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li></ul>';
myList = document.getElementById('my-list');
for(var i =0, len = myList.childNodes.length; i < len; i++){ var thisChild = myList.childNodes[i];
// remove the list for testing purposes myWrapper.innerHTML='';
pending…
Batched Reflows
// first add the list, for testing purposes myWrapper.innerHTML='<ul id="my-list"><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li></ul>';
myList = document.getElementById('my-list');
myList.style.display='none';
for(var i =0, len = myList.childNodes.length; i < len; i++){ var thisChild = myList.childNodes[i];
0 comments