[英]Force Chrome to refresh display during javascript execution
I have to create a jQuery Dynatree. 我必须创建一个jQuery Dynatree。 With my JavaScript, I build the different nodes of this Dynatree as I go along.
继续使用JavaScript,我可以构建此Dynatree的不同节点。 The JavaScript execution takes a certain time.
JavaScript执行需要一定的时间。
In Firefox, I get the result I want ie I see my Dynatree growing but in Chrome, I have to wait until the end of the JavaScript execution to see the final result. 在Firefox中,我得到了想要的结果,即看到Dynatree在增长,但是在Chrome中,我必须等到JavaScript执行结束后才能看到最终结果。 Before that I have only a blank page.
在此之前,我只有空白页。
So do you know a way to force Chrome to refresh display during JavaScript execution? 那么,您是否知道一种强制Chrome在JavaScript执行期间刷新显示的方法?
I assume you're using a loop to generate the tree, thus create a function that runs a single step of the tree growth based on a variable passed being what would have been your counter in the loop. 我假设您正在使用循环来生成树,从而基于传递的变量(即循环中的计数器)创建一个运行树生长的单个步骤的函数。 ei:
ei:
<script>
// what you probably have now
// for(var i=0;i<100;i++){
// dosomething
// };
function step(i){
dosomething
if(i<100){
window.requestAnimationFrame(function(){step(i+1)});
};
};
step(0);
</script>
You will have to make requestAnimationFrame
cross browser like so. 您将必须像这样使
requestAnimationFrame
跨浏览器。
window.requestAnimationFrame=(function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback){
window.setTimeout(callback,1000/45);
};
})();
But this should work and re-render the DOM after each time the program is run. 但这应该可以工作,并在每次运行程序后重新呈现DOM。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.