Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safari cannot find requestAnimationFrame #72

Closed
codeanticode opened this issue Oct 8, 2013 · 4 comments
Closed

Safari cannot find requestAnimationFrame #72

codeanticode opened this issue Oct 8, 2013 · 4 comments

Comments

@codeanticode
Copy link
Member

I tried to run pjs script using different versions of Safari, including the latest one included in 10.8.5, and get the following error:

pjs.js:1605 ReferenceError: Can't find variable: requestAnimationFrame

which corresponds to the following code in pjs.js:

if (pLoop) {
  setTimeout(function() {
    requestAnimationFrame(pDraw);
  }, 1000 / frameRate);
}

Part of https://github.com/lmccart/processing-js/issues/20

@taseenb
Copy link
Contributor

taseenb commented Oct 9, 2013

In the last Safari it still requires the "webkit" prefix. You can use something like this to make sure it works (almost) everywhere:

// requestAnim shim layer by Paul Irish
window.requestAnimFrame = (function(){
  return  window.requestAnimationFrame       || 
          window.webkitRequestAnimationFrame || 
          window.mozRequestAnimationFrame    || 
          window.oRequestAnimationFrame      || 
          window.msRequestAnimationFrame     || 
          function(/* function */ callback, /* DOMElement */ element){
              window.setTimeout(callback, 1000 / 60);
          };
})();

Browser support: http://caniuse.com/requestanimationframe

@lmccart
Copy link
Member

lmccart commented Oct 10, 2013

thanks @taseenb! @codeanticode do you want to try this in your version of safari and close if it works? we haven't really been testing in anything other than chrome yet, but this is a great start.

@codeanticode
Copy link
Member Author

this pr should fix it https://github.com/lmccart/processing-js/pull/74, I tested on safari 6.0.5 only.

@lmccart
Copy link
Member

lmccart commented Oct 10, 2013

oh wow I didn't hook that last attempt of mine in correctly at all, must be very tired, sorry about that. thanks for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants