发生什么事情可以让循环的其余部分执行,然后让requestAnimationFrame执行下一帧?为什么在循环开始时调用requestAnimationFrame不会导致无限递归?
我误解了这种方法是如何工作的,并且无法在任何地方看到明确的解释。我尝试阅读这里的时序规范http://www.w3.org/TR/animation-timing/,但我无法弄清楚它是如何工作的。
编辑:
例如,此代码取自threejs文档。
var render = function() {
requestAnimationFrame(render);
cube.rotation.x += 0.1;
cube.rotation.y += 0.1;
renderer.render(scene, camera);
};
你可以发表一些代码吗? –
[请求动画帧以获得更佳性能](http://html5hub.com/request-animation-frame-for-better-performance/),[用于智能动画制作的requestAnimationFrame](http://www.paulirish.com/2011/requestanimationframe-for-smart-animating /) – Andreas
requestAnimationFrame不是递归的,它是异步的(就像一个简短的setTimeout,但更有效率),并在被调用的函数的主体之后执行。但是,它在for循环。顺便说一句,递归发生在render函数中,而不是在requestAnimationFrame中,你不是在render中调用render。 – mpm