Questions tagged «requestanimationframe»

9
用requestAnimationFrame控制fps?
现在看来似乎requestAnimationFrame是事实上的动画方法。在大多数情况下,它对我来说效果很好,但是现在我正在尝试制作一些画布动画,我在想:是否有任何方法可以确保它以特定的fps运行?我了解到rAF的目的是使动画始终保持平滑,并且可能冒使动画不稳定的风险,但是现在看来它以任意不同的速度运行,我想知道是否有一种方法可以打击那不知何故。 我会用,setInterval但是我想要rAF提供的优化(尤其是在标签页处于焦点时自动停止)。 如果有人想看一下我的代码,那就差不多了: animateFlash: function() { ctx_fg.clearRect(0,0,canvasWidth,canvasHeight); ctx_fg.fillStyle = 'rgba(177,39,116,1)'; ctx_fg.strokeStyle = 'none'; ctx_fg.beginPath(); for(var i in nodes) { nodes[i].drawFlash(); } ctx_fg.fill(); ctx_fg.closePath(); var instance = this; var rafID = requestAnimationFrame(function(){ instance.animateFlash(); }) var unfinishedNodes = nodes.filter(function(elem){ return elem.timer < timerMax; }); if(unfinishedNodes.length === 0) { console.log("done"); cancelAnimationFrame(rafID); instance.animate(); } …

3
jQuery为什么不使用requestAnimationFrame?
一些浏览器支持requestAnimationFrame,那么为什么不使用它呢?毕竟,自Google Chrome 10以来一直受支持。尽管如此,jQuery似乎并未使用它。我已经找到有关它的错误报告,但是没有给出真正的解释?我确信jQuery的人有他们的理由。 他们为什么不使用这个很棒的API?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.