[英]Force repaint during Javascript loop
I want to force a repaint during a Javascript loop. 我想在Javascript循环中强制重绘。 For example: 例如:
var s = document.getElementById("foo");
for (var i = 0; i < 10000; i++)
s.innerText = i + " times";
That updates at the end, but I would like to observe each intermediate step. 最后更新,但是我想观察每个中间步骤。 The common response to this problem is to use setTimeout
, however, there are three reasons that is unacceptable: 解决此问题的常见方法是使用setTimeout
,但是有三个不可接受的原因:
Is there a way to force the browser to repaint? 有没有办法强制浏览器重新粉刷?
I'm afraid this is your only solution though, since the non-repaintable-in-the-middle is something important as a predicate for speed gains in rendering of browsers. 恐怕这是您唯一的解决方案,因为不可重画的中间内容作为提高浏览器渲染速度的谓词很重要。
Perhaps could you manage a buffer-me flag in those click events you don't want to fire? 也许您可以在您不想触发的那些单击事件中管理“缓冲我”标志? Or better said a dont-buffer-me flag... 或者更好的说一个不要缓冲我的标志...
I hope it helped, best regards. 希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.