做一次发生针对每个应用的样式回流? [英] do reflows occur once for each applied style?

查看:104
本文介绍了做一次发生针对每个应用的样式回流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我这样做在JavaScript:

  element.style.width =100px的;
element.style.height =100px的;

我是正确地说,有2回流文档中?

如果我这样做:

element.setAttribute(风格,宽度:100像素,高度:100像素;)?只有1回流

(我知道后面会简单地覆盖所有其他previously设置样式)

侧的问题:有没有什么办法,我们可以停止猜测,并检查到底有多少回流在浏览器中正在发生的事情(铬/ FF /等)


解决方案

  

当我这样做在JavaScript:


  
  

element.style.width =100px的结果
  element.style.height =100px的;


  
  

我是正确地说,有2回流文档中?


最不可能的。回流取(相对)大量的时间,所以他们往往当他们需要,例如只有JavaScript执行期间发生时,一段JavaScript代码读回依赖于它的布局,例如财产offsetWidth。

但细节将依赖于实现

When i do this in javascript:

element.style.width="100px";
element.style.height="100px";

Am i right to say that there are 2 reflows in the document?

And if i do this:

element.setAttribute("style","width:100px;height:100px;") there is only 1 reflow?

(I am aware that the latter will simply override all other previously set styles)

Side question: is there any way we can stop the guessing and inspect exactly how many reflows is happening in the browser (Chrome / FF / etc)?

解决方案

When i do this in javascript:

element.style.width="100px";
element.style.height="100px";

Am i right to say that there are 2 reflows in the document?

Most unlikely. Reflows take (comparatively) a lot of time so they tend to only happen during JavaScript execution when they need to, for example when a piece of JavaScript reads back a property that depends on it's layout, e.g. offsetWidth.

But the details will be implementation dependent.

这篇关于做一次发生针对每个应用的样式回流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆