javascript - 如果我将 appendChild() 与尚未附加到 DOM 的元素一起使用,它会导致重排吗?
问题描述
例如,在这段代码中,该行是否myCustomDiv.appendChild(newElement);
会导致回流?我认为它没有,因为该元素尚未附加到 DOM,但我在某处读到它确实会导致回流,那么为什么会发生这种情况?
const myCustomDiv = document.createElement('div');
for (let i = 1; i <= 200; i++) {
const newElement = document.createElement('p');
newElement.innerText = 'This is paragraph number ' + i;
myCustomDiv.appendChild(newElement);
}
document.body.appendChild(myCustomDiv);
解决方案
推荐阅读
- r - 使用 pheatmap 包在热图中添加带有黑色或边框线的间隙
- flutter - 返回类型“对象?” 不是闭包上下文所要求的“小部件”。扑
- testing - 如何测试 v-text-field 的值和显示?
- javascript - 如何在 React 组件中导入的非组件类中使用 props 值
- pine-script - 是否可以使用 barsince 来获得 Pine 的先前低点或高点?
- hana - 从 ADX 查询 SAP HANA 表
- android - 如何使用 Jetpack Compose 隐藏 ActionBar
- python - SymPy 中的相同表达式不是 ==
- haskell - 创建列表后如何在 Haskell 中获取列表的长度?
- android-jetpack-compose - 在 Jetpack Compose 中使用可变对象