├── .gitignore ├── LICENSE ├── README.md ├── build.sh ├── requestAnimationFrame.js └── requestAnimationFrame.min.js /.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | 10 | pids 11 | logs 12 | results 13 | 14 | npm-debug.log 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2011-2013 Erik Möller, Paul Irish, Tino Zijdel, Andrew Mao, Klemen Slavič, Darius Bacon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | requestAnimationFrame 2 | ===================== 3 | > requestAnimationFrame polyfill by [Erik Möller](https://twitter.com/erikjmoller). 4 | 5 | Polyfill for 6 | [requestAnimationFrame](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) 7 | and cancelAnimationFrame. That is, load the included .js file to make those 8 | functions work (more or less) even on older systems that do not natively supply 9 | them. 10 | 11 | This version of the code is only lightly tested. It's provoked no 12 | complaints since the initial checkin of 2013-9-16, but it hasn't been 13 | deliberately tested on a zillion targets either. 14 | 15 | ## Credits 16 | Fixes from [Paul Irish](https://github.com/paulirish), [Tino Zijdel](https://twitter.com/tinozijdel), [Andrew Mao](https://github.com/mizzao), [Klemen Slavič](https://github.com/KrofDrakula), [Darius Bacon](https://github.com/darius) 17 | 18 | Adapted from https://gist.github.com/paulirish/1579671 which is derived from: 19 | - http://paulirish.com/2011/requestanimationframe-for-smart-animating/ 20 | - http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating 21 | 22 | ## To do 23 | - Incorporate improvements from: 24 | - http://stackoverflow.com/questions/13241314/up-to-date-polyfill-for-requestanimationframe 25 | - https://gist.github.com/mrdoob/838785 26 | 27 | ## Support 28 | [Supported browsers](http://caniuse.com/requestanimationframe) 29 | 30 | ## Contributing 31 | 32 | Pull requests welcome. 33 | Please respect the code style in place. 34 | 35 | ## License 36 | 37 | MIT License 38 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | uglifyjs requestAnimationFrame.js -m >requestAnimationFrame.min.js 2 | -------------------------------------------------------------------------------- /requestAnimationFrame.js: -------------------------------------------------------------------------------- 1 | // Adapted from https://gist.github.com/paulirish/1579671 which derived from 2 | // http://paulirish.com/2011/requestanimationframe-for-smart-animating/ 3 | // http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating 4 | 5 | // requestAnimationFrame polyfill by Erik Möller. 6 | // Fixes from Paul Irish, Tino Zijdel, Andrew Mao, Klemen Slavič, Darius Bacon 7 | 8 | // MIT license 9 | 10 | if (!Date.now) 11 | Date.now = function() { return new Date().getTime(); }; 12 | 13 | (function() { 14 | 'use strict'; 15 | 16 | var vendors = ['webkit', 'moz']; 17 | for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) { 18 | var vp = vendors[i]; 19 | window.requestAnimationFrame = window[vp+'RequestAnimationFrame']; 20 | window.cancelAnimationFrame = (window[vp+'CancelAnimationFrame'] 21 | || window[vp+'CancelRequestAnimationFrame']); 22 | } 23 | if (/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent) // iOS6 is buggy 24 | || !window.requestAnimationFrame || !window.cancelAnimationFrame) { 25 | var lastTime = 0; 26 | window.requestAnimationFrame = function(callback) { 27 | var now = Date.now(); 28 | var nextTime = Math.max(lastTime + 16, now); 29 | return setTimeout(function() { callback(lastTime = nextTime); }, 30 | nextTime - now); 31 | }; 32 | window.cancelAnimationFrame = clearTimeout; 33 | } 34 | }()); 35 | -------------------------------------------------------------------------------- /requestAnimationFrame.min.js: -------------------------------------------------------------------------------- 1 | "use strict";if(!Date.now)Date.now=function(){return(new Date).getTime()};(function(){var n=["webkit","moz"];for(var e=0;e