如果您愿意,可以随意提出有关如何模拟旧供应商特定行为的问题。
Chrome,Firefox,Internet Explorer和Opera可能分别为requestAnimationFrame
提供不同的功能:
webkitRequestAnimationFrame
mozRequestAnimationFrame
msRequestAnimationFrame
oRequestAnimationFrame
specification非常清楚他们应该分享什么样的行为,但有没有人对他们的差异有一个权威的答案?
编辑:暂时,我接受了我自己的答案。我仍然对IE 10的实现细节感兴趣,并且,如果Opera实现它,Opera的;如果存在任何重大差异,我会更新问题。答案 0 :(得分:1)
我找到的最好的资源是
https://developer.mozilla.org/en/DOM/window.requestAnimationFrame
仅解决webkit
和moz
变体。
moz
:您可以在没有参数的情况下致电requestAnimationFrame
;这将导致在浏览器准备好绘制动画帧时触发MozBeforePaint
个事件。
window.mozRequestAnimationFrame();
window.addEventListener("MozBeforePaint", function(event){
//event.timeStamp has the next repaint time
/* animation code here*/
}, false);
webkit
:您可以使用第二个参数调用requestAnimationFrame
,该参数应该是动画的DOM元素;这将导致只有在DOM元素可见时才会调用动画函数。
(适用于Chrome)Example:您可以通过打开控制台并观察动画函数发出的日志消息仅在画布可见时生成,来判断它是否有效。
这使Opera和IE变体无法解决。
答案 1 :(得分:1)
也许是完整解释的最佳页面is this one。