如果您确实需要回流,可以对其进行优化

时间:2018-12-09 02:42:07

标签: javascript performance dom requestanimationframe

在我的代码中,我必须删除一个类,以获取其完整高度。这是在requestAnimationFrame中完成的,但是先删除该类然后再查询scrollHeight,将强制重排。我是否只需要在scrollHeight中查询setTimeout

requestAnimationFrame(() => {
  poo.style.overflow = 'visible';
  poo.scrollHeight;
  // Do something with it
  poo.style.overflow = 'auto';
});

进入...?

requestAnimationFrame(() => {
  poo.style.overflow = 'visible';

  setTimeout(() => {
    poo.scrollHeight;
    // Do something with it
    poo.style.overflow = 'auto';
  }, 0);
});

0 个答案:

没有答案