diff options
Diffstat (limited to 'src/ng')
| -rw-r--r-- | src/ng/raf.js | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/ng/raf.js b/src/ng/raf.js index f85ee12a..0bc43f34 100644 --- a/src/ng/raf.js +++ b/src/ng/raf.js @@ -1,21 +1,29 @@ 'use strict'; function $$RAFProvider(){ //rAF - this.$get = ['$window', function($window) { + this.$get = ['$window', '$timeout', function($window, $timeout) { var requestAnimationFrame = $window.requestAnimationFrame || $window.webkitRequestAnimationFrame; var cancelAnimationFrame = $window.cancelAnimationFrame || $window.webkitCancelAnimationFrame; - var raf = function(fn) { - var id = requestAnimationFrame(fn); - return function() { - cancelAnimationFrame(id); - }; - }; + var rafSupported = !!requestAnimationFrame; + var raf = rafSupported + ? function(fn) { + var id = requestAnimationFrame(fn); + return function() { + cancelAnimationFrame(id); + }; + } + : function(fn) { + var timer = $timeout(fn, 16.66, false); // 1000 / 60 = 16.666 + return function() { + $timeout.cancel(timer); + }; + }; - raf.supported = !!requestAnimationFrame; + raf.supported = rafSupported; return raf; }]; |
