简体   繁体   English

关于DOM Reflow的快速入门

[英]Quick one about DOM Reflow

If I have an image set to display none; 如果我将图像设置为不显示; eg: 例如:

#myImg {position:absolute;left:100px;top:100px;display:none;}

And I move it with Js like so: 我像这样用Js移动它:

function Move ()
{var pic=document.getElementById ("myImg");
 myImg.style.left=200+'px';
 myImg.style.top=200+'px';
}

Does it cause a reflow even though it's set to 'display:none'? 即使将其设置为“ display:none”,它是否也会导致重排?

And what about visibility:hidden? 可见性如何:隐藏?

In my previous post I boldly claimed that elements with display: none will not have anything to do with the render tree. 在我以前的文章中,我大胆地宣称带有display的元素:没有任何元素与渲染树有任何关系。 IE begs to differ (thanks to dynaTrace folks for pointing that out). IE要求有所不同(感谢dynaTrace人士指出了这一点)。

A good way to minimize reflows is to update the DOM tree "offline" out of the live document. 最小化重排的一个好方法是从活动文档中更新DOM树“离线”。 One way to do so is to hide the element while updates are taking place and then show it again. 一种方法是在进行更新时隐藏元素,然后再次显示它。

Check out http://www.phpied.com/the-new-game-show-will-it-reflow/ 查看http://www.phpied.com/the-new-game-show-will-it-reflow/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM