For which browsers are we using Paul Irish's requestAnimationFrame shim?

ぐ巨炮叔叔 提交于 2020-01-01 08:03:41

问题


Paul Irish has a post called requestAnimationFrame for Smart Animating. Now Paul is a smart guy - and I'm just trying to understand the scope of the application of this idea.

He says to do HTML5 animation - you should use a requestAnimationFrame shim like this:

// shim layer with setTimeout fallback
window.requestAnimFrame = (function(){
  return  window.requestAnimationFrame       ||
      window.webkitRequestAnimationFrame ||
      window.mozRequestAnimationFrame    ||
      function( callback ){
        window.setTimeout(callback, 1000 / 60);
      };
})();


// usage:
// instead of setInterval(render, 16) ....

(function animloop(){
  requestAnimFrame(animloop);
  render();
})();
// place the rAF *before* the render() to assure as close to
// 60fps with the setTimeout fallback.

Which is understandable. We can apply this in a JSFiddle like this and the results are quite good.

But if I rip out the shim layer function, then in Chrome 31 and Firefox 24 it works fine.

So if I look at the compatibility for the RequestAnimationFrame function - it looks like browsers have had this function for a very long time.

My question is - For which browsers are we using Paul Irish's requestAnimationFrame shim? You can rip it out and it still works, and it looks like browsers have had it for a long time.


回答1:


I'm afraid the polyfill/shim will be necessary if you want to support older browsers.

As you point out, it works with latest Firefox and Chrome without prefix. Firefox has also a new policy not to prefix any future technology so that's perhaps a good thing too and there is a proposal to do the same for Chrome.

But if you run older browsers (and a surprisingly large group of users do) the polyfill is necessary.

Source

Here we see IE9 on top followed by IE8, 10 and then older Chrome versions (although this includes the whole last year which explains the Chrome part and also IE9 vs. IE10). Variations may apply to regions so test out the geographic area where you think your application is relevant.




回答2:


You need the polyfill for IE8, IE9, Android Browser, and a bunch of older stuff you'd have to make a judgement call on.

Here's the current support for rAF thanks to caniuse.com:

Anything with a yellow flag in the corner uses a prefix so it needs the shim. Anything red needs the setTimeout fallback.

But, to get at your core point... soon, yes, soon, the polyfill will be much smaller. And hopefully not too long from now we can kill it and use rAF directly.



来源:https://stackoverflow.com/questions/21177323/for-which-browsers-are-we-using-paul-irishs-requestanimationframe-shim

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!